Skip to content

Commit

Permalink
Merge pull request #4180 from fivetanley/ams-updates-1-13
Browse files Browse the repository at this point in the history
[BUGFIX release-1-13] JSONAPI serializer not respecting 'attrs' hash
  • Loading branch information
fivetanley committed Feb 22, 2016
2 parents bad41ad + 216fbc4 commit 8d315e6
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,67 @@ test('Serializer should respect the attrs hash when serializing attributes and r
equal(payload.data.attributes['title_attribute_key'], "director");
});

test('Serializer should respect the attrs hash when extracting attributes and relationships', function() {
env.registry.register("serializer:user", DS.JSONAPISerializer.extend({
attrs: {
title: "title_attribute_key",
company: { key: 'company_relationship_key' }
}
}));

var jsonHash = {
data: {
type: 'users',
id: '1',
attributes: {
'title_attribute_key': 'director'
},
relationships: {
'company_relationship_key': {
data: { type: 'companies', id: '2' }
}
}
},
included: [{
type: 'companies',
id: '2',
attributes: {
name: 'Tilde Inc.'
}
}]
};

var user = env.store.serializerFor("user").normalizeResponse(env.store, User, jsonHash, '1', 'findRecord');

equal(user.data.attributes.title, "director");
deepEqual(user.data.relationships.company.data, { id: "2", type: "company" });
});

test('Serializer should respect the attrs hash when serializing attributes and relationships', function() {
env.registry.register("serializer:user", DS.JSONAPISerializer.extend({
attrs: {
title: "title_attribute_key",
company: { key: 'company_relationship_key' }
}
}));
var company, user;

run(function() {
env.store.push({
data: {
type: 'company',
id: '1',
attributes: {
name: "Tilde Inc."
}
}
});
company = env.store.peekRecord('company', 1);
user = env.store.createRecord('user', { firstName: "Yehuda", title: "director", company: company });
});

var payload = env.store.serializerFor("user").serialize(user._createSnapshot());

equal(payload.data.relationships['company_relationship_key'].data.id, "1");
equal(payload.data.attributes['title_attribute_key'], "director");
});

0 comments on commit 8d315e6

Please sign in to comment.