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

Deprecate normalizeHash method on the rest serializer #4258

Merged
merged 1 commit into from
Mar 24, 2016
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
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/);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much indentation, such ocd

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good 👀

});


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