Skip to content

Commit

Permalink
[BUGFIX] Pass options to transform for serialization in json-api
Browse files Browse the repository at this point in the history
Since json serializer's serializeAttribute function is been overwritten in json api serializer, the feature to pass the options to the transform is not working when using the json api adapter. This fixes the problem.
  • Loading branch information
josemarluedke committed Jun 8, 2016
1 parent e4758d3 commit 58132ae
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 58132ae

Please sign in to comment.