Skip to content

Commit

Permalink
[CLEANUP beta] Remove support/deprecation for normalizeHash in 3.0.0 (#…
Browse files Browse the repository at this point in the history
…5289)

(cherry picked from commit a80709c)
  • Loading branch information
bmac committed Feb 12, 2018
1 parent 595783f commit 608d7f3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 120 deletions.
10 changes: 0 additions & 10 deletions addon/serializers/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,6 @@ const RESTSerializer = JSONSerializer.extend({
@param {String} prop
@return {Object}
*/
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);
},

/**
Normalizes an array of resource payloads and returns a JSON-API Document
Expand Down
110 changes: 0 additions & 110 deletions tests/integration/serializers/rest-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,116 +374,6 @@ test("normalizeResponse loads secondary records with correct serializer", functi
assert.equal(superVillainNormalizeCount, 1, "superVillain is normalized once");
});

testInDebug('normalizeHash normalizes specific parts of the payload (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] }]
};
var array;

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

assert.deepEqual(array, {
"data": [{
"id": "1",
"type": "home-planet",
"attributes": {
"name": "Umber"
},
"relationships": {
"superVillains": {
"data": [
{ "id": "1", "type": "super-villain" }
]
}
}
}],
"included": []
});

});

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/);
});
});


testInDebug('normalizeHash works with transforms (DEPRECATED)', function(assert) {
env.registry.register('serializer:application', DS.RESTSerializer.extend({
normalizeHash: {
evilMinions(hash) {
hash.condition = hash._condition;
delete hash._condition;
return hash;
}
}
}));

env.registry.register('transform:condition', DS.Transform.extend({
deserialize(serialized) {
if (serialized === 1) {
return "healing";
} else {
return "unknown";
}
},
serialize(deserialized) {
if (deserialized === "healing") {
return 1;
} else {
return 2;
}
}
}));

EvilMinion.reopen({ condition: DS.attr('condition') });

var jsonHash = {
evilMinions: [{ id: "1", name: "Tom Dale", superVillain: 1, _condition: 1 }]
};
var array;

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

assert.equal(array.data[0].attributes.condition, "healing");
});

test('normalize should allow for different levels of normalization', function(assert) {
env.registry.register('serializer:application', DS.RESTSerializer.extend({
attrs: {
Expand Down

0 comments on commit 608d7f3

Please sign in to comment.