Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #3955 #3956

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addon/serializers/json-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,11 @@ export default Serializer.extend({
*/
normalizeUsingDeclaredMapping: function(modelClass, hash) {
var attrs = get(this, 'attrs');
var payloadKey, normalizedKey, key;
var normalizedKey, payloadKey, key;

if (attrs) {
for (key in attrs) {
payloadKey = this._getMappedKey(key, modelClass);
normalizedKey = payloadKey = this._getMappedKey(key, modelClass);

if (!hash.hasOwnProperty(payloadKey)) { continue; }

Expand Down
21 changes: 21 additions & 0 deletions tests/integration/serializers/json-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,3 +885,24 @@ test('normalizeResponse respects `included` items (array response)', function(as
{ id: "3", type: "comment", attributes: { body: "comment 3" }, relationships: {} }
]);
});

test('normalizeResponse ignores unmapped attributes', function(assert) {
env.registry.register("serializer:post", DS.JSONSerializer.extend({
attrs: {
title: { serialize: false },
notInMapping: { serialize: false }
}
}));

var jsonHash = {
id: "1",
notInMapping: 'I should be ignored',
title: "Rails is omakase"
};

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

assert.equal(post.data.attributes.title, "Rails is omakase");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curious, but according to the test description, it looks like there should be an assertion which checks that notInMapping is not serialized, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I suppose there should be an assert that checks it isn't added, but the primary problem this PR is trying to fix is that the value of notInMapping gets assigned to the title key.

});