Skip to content

Commit

Permalink
Deprecate normalizeHash method on the rest serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
bmac committed Mar 23, 2016
1 parent e844222 commit de43c2c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addon/serializers/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ var RESTSerializer = JSONSerializer.extend({
*/
normalize(modelClass, resourceHash, prop) {
if (this.normalizeHash && this.normalizeHash[prop]) {
deprecate('`RESTSerializer.normalizeHash` has been deprecated. Please use `serializer.normalize` to modify the payload of single resources.', false, {
id: 'ds.serializer.normalize-hash-deprecated',
until: '3.0.0'
});
this.normalizeHash[prop](resourceHash);
}
return this._super(modelClass, resourceHash);
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/serializers/rest-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,29 @@ test('normalizeHash normalizes specific parts of the payload', function(assert)

});

testInDebug('normalizeHash has been deprecated', function(assert) {
env.registry.register('serializer:application', DS.RESTSerializer.extend({
normalizeHash: {
homePlanets(hash) {
hash.id = hash._id;
delete hash._id;
return hash;
}
}
}));

var jsonHash = {
homePlanets: [{ _id: "1", name: "Umber", superVillains: [1] }]
};

run(function() {
assert.expectDeprecation(function() {
env.restSerializer.normalizeResponse(env.store, HomePlanet, jsonHash, null, 'findAll');
}, /`RESTSerializer.normalizeHash` has been deprecated/);
});
});


test('normalizeHash works with transforms', function(assert) {
env.registry.register('serializer:application', DS.RESTSerializer.extend({
normalizeHash: {
Expand Down

0 comments on commit de43c2c

Please sign in to comment.