Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert if the RESTSerializers when using the new format calls another #3384

Merged
merged 1 commit into from
Jun 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Expand Down Expand Up @@ -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);
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./);
});