From 72a6290b50a5e8c01034d283ce177098ee4ceb29 Mon Sep 17 00:00:00 2001 From: Julian Paas Date: Fri, 27 Nov 2015 11:58:03 -0500 Subject: [PATCH] [BUGFIX beta] ignores keys that are not found in the map --- addon/-private/serializers/json-serializer.js | 4 ++-- .../serializers/json-serializer-test.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/addon/-private/serializers/json-serializer.js b/addon/-private/serializers/json-serializer.js index b43aafb0dc9..0eb2389897a 100644 --- a/addon/-private/serializers/json-serializer.js +++ b/addon/-private/serializers/json-serializer.js @@ -728,11 +728,11 @@ export default Serializer.extend({ */ normalizeUsingDeclaredMapping(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; } diff --git a/tests/integration/serializers/json-serializer-test.js b/tests/integration/serializers/json-serializer-test.js index 1af7b5f0a33..b926f828593 100644 --- a/tests/integration/serializers/json-serializer-test.js +++ b/tests/integration/serializers/json-serializer-test.js @@ -885,3 +885,22 @@ 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"); +});