Skip to content

Commit

Permalink
Merge pull request #4425 from josemarluedke/fix-transform-option-for-…
Browse files Browse the repository at this point in the history
…json-api

[BUGFIX] Pass options to transform for serialization in json-api
  • Loading branch information
bmac committed Jun 9, 2016
2 parents 60b8ea2 + 58132ae commit 1345da1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon/serializers/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ const JSONAPISerializer = JSONSerializer.extend({
let value = snapshot.attr(key);
if (type) {
const transform = this.transformFor(type);
value = transform.serialize(value);
value = transform.serialize(value, attribute.options);
}

let payloadKey = this._getMappedKey(key, snapshot.type);
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/serializers/json-api-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,28 @@ test('Serializer should respect the attrs hash when serializing attributes with
assert.equal(payload.data.attributes['company_name'], 'Tilde Inc.');
});

test('options are passed to transform for serialization', function(assert) {
assert.expect(1);

env.registry.register('transform:custom', DS.Transform.extend({
serialize: function(deserialized, options) {
assert.deepEqual(options, { custom: 'config' });
}
}));

User.reopen({
myCustomField: DS.attr('custom', {
custom: 'config'
})
});

var user;
run(function() {
user = env.store.createRecord('user', { myCustomField: 'value' });
});

env.store.serializerFor('user').serialize(user._createSnapshot());
});

testInDebug('JSON warns when combined with EmbeddedRecordsMixin', function(assert) {
assert.expectWarning(function() {
Expand Down

0 comments on commit 1345da1

Please sign in to comment.