Skip to content

Commit

Permalink
Assert if the RESTSerializers when using the new format calls another
Browse files Browse the repository at this point in the history
serializer that does not use the new format.
  • Loading branch information
bmac committed Jun 18, 2015
1 parent d9585c8 commit 03e4f7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/ember-data/lib/serializers/rest-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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./);
});

0 comments on commit 03e4f7b

Please sign in to comment.