diff --git a/packages/ember-data/lib/serializers/rest-serializer.js b/packages/ember-data/lib/serializers/rest-serializer.js index 345c5f7ae89..c7a3a4b4961 100644 --- a/packages/ember-data/lib/serializers/rest-serializer.js +++ b/packages/ember-data/lib/serializers/rest-serializer.js @@ -9,6 +9,7 @@ import coerceId from "ember-data/system/coerce-id"; import { pushPayload } from "ember-data/system/store/serializer-response"; var camelize = Ember.String.camelize; +var get = Ember.get; /** Normally, applications will use the `RESTSerializer` by implementing @@ -212,6 +213,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')); + arrayHash.forEach((hash) => { let { data, included } = serializer.normalize(modelClass, hash, prop); documentHash.data.push(data); 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./); +});