From 03e4f7b81aa2cf3dc04a5bc114097fbf2e8daae0 Mon Sep 17 00:00:00 2001 From: bmac Date: Thu, 18 Jun 2015 12:42:01 -0400 Subject: [PATCH] Assert if the RESTSerializers when using the new format calls another serializer that does not use the new format. --- .../lib/serializers/rest-serializer.js | 3 +++ .../serializers/rest-serializer-new-test.js | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/ember-data/lib/serializers/rest-serializer.js b/packages/ember-data/lib/serializers/rest-serializer.js index 713f721137b..2a84a6a44b2 100644 --- a/packages/ember-data/lib/serializers/rest-serializer.js +++ b/packages/ember-data/lib/serializers/rest-serializer.js @@ -11,6 +11,7 @@ import { pushPayload } from "ember-data/system/store/serializer-response"; var forEach = Ember.ArrayPolyfills.forEach; var map = Ember.ArrayPolyfills.map; var camelize = Ember.String.camelize; +var get = Ember.get; /** Normally, applications will use the `RESTSerializer` by implementing @@ -214,6 +215,8 @@ var RESTSerializer = JSONSerializer.extend({ let modelClass = store.modelFor(modelName); let serializer = store.serializerFor(modelName); + Ember.assert(`${this.toString()} has opted into the new serializer API and expects the ${serializer.toString()} it collaborates with to also support the new serializer API by setting its \`isNewSerializerAPI\` property to true.`, get(serializer, 'isNewSerializerAPI')); + /*jshint loopfunc:true*/ forEach.call(arrayHash, (hash) => { let { data, included } = serializer.normalize(modelClass, hash, prop); diff --git a/packages/ember-data/tests/integration/serializers/rest-serializer-new-test.js b/packages/ember-data/tests/integration/serializers/rest-serializer-new-test.js index a3d6227a80b..40178174b21 100644 --- a/packages/ember-data/tests/integration/serializers/rest-serializer-new-test.js +++ b/packages/ember-data/tests/integration/serializers/rest-serializer-new-test.js @@ -409,3 +409,24 @@ test('normalize should allow for different levels of normalization', function() equal(array.data[0].relationships.superVillain.data.id, 1); }); + + +test("should assert with collaborating with non newSerializerAPI serializers", function() { + expect(1); + + env.registry.register('serializer:home-planet', DS.RESTSerializer.extend({ + isNewSerializerAPI: false + })); + + + var jsonHash = { + home_planets: [{ id: "1", name: "Umber", superVillains: [1] }], + super_villains: [{ id: "1", firstName: "Tom", lastName: "Dale", homePlanet: "1" }] + }; + var array; + expectAssertion(function() { + run(function() { + array = env.restNewSerializer.normalizeArrayResponse(env.store, SuperVillain, jsonHash, null, 'findAll'); + }); + }, /collaborates with to also support the new serializer API by setting its `isNewSerializerAPI` property to true./); +});