From a8791733ac54ba0cb6773ebeb46a3aa3319273fc Mon Sep 17 00:00:00 2001 From: pangratz Date: Mon, 4 May 2015 10:20:41 +0200 Subject: [PATCH] JSONSerializer#extractErrors respects custom key mappings Custom key mappings defined in the `attrs` hash of the JSONSerializer are now considered when extracting errors. --- .../lib/serializers/json-serializer.js | 1 + .../serializers/json-serializer-test.js | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/ember-data/lib/serializers/json-serializer.js b/packages/ember-data/lib/serializers/json-serializer.js index ea101eb9e21..4f501546343 100644 --- a/packages/ember-data/lib/serializers/json-serializer.js +++ b/packages/ember-data/lib/serializers/json-serializer.js @@ -274,6 +274,7 @@ export default Serializer.extend({ this.normalizeId(hash); this.normalizeAttributes(typeClass, hash); this.normalizeRelationships(typeClass, hash); + this.normalizeUsingDeclaredMapping(typeClass, hash); }, /** diff --git a/packages/ember-data/tests/integration/serializers/json-serializer-test.js b/packages/ember-data/tests/integration/serializers/json-serializer-test.js index 7a7af6450aa..0a7f2acfd84 100644 --- a/packages/ember-data/tests/integration/serializers/json-serializer-test.js +++ b/packages/ember-data/tests/integration/serializers/json-serializer-test.js @@ -454,3 +454,26 @@ test('serializeBelongsTo with async polymorphic', function() { deepEqual(json, expected, 'returned JSON is correct'); }); + +test('extractErrors respects custom key mappings', function() { + env.registry.register('serializer:post', DS.JSONSerializer.extend({ + attrs: { + title: 'le_title', + comments: { key: 'my_comments' } + } + })); + + var payload = { + errors: { + le_title: ["title errors"], + my_comments: ["comments errors"] + } + }; + + var errors = env.container.lookup('serializer:post').extractErrors(env.store, Post, payload); + + deepEqual(errors, { + title: ["title errors"], + comments: ["comments errors"] + }); +});