Skip to content

Commit

Permalink
Merge pull request #3055 from omghax/merge-attrs-from-superclasses
Browse files Browse the repository at this point in the history
Merge `attrs` from superclasses into their subclasses.
  • Loading branch information
igorT committed May 8, 2015
2 parents 51bac6a + 4e4b97a commit 7d7c55d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/ember-data/lib/serializers/json-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default Serializer.extend({
@property attrs
@type {Object}
*/
mergedProperties: ['attrs'],

/**
Given a subclass of `DS.Model` and a JSON object this method will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,32 @@ test('Serializer respects `serialize: false` on the attrs hash for a `belongsTo`
ok(!payload.hasOwnProperty(serializedProperty), "Does not add the key to instance");
});

test("Serializer should merge attrs from superclasses", function() {
expect(2);
Post.reopen({
description: DS.attr('string')
});
var BaseSerializer = DS.JSONSerializer.extend({
attrs: {
title: "title_payload_key"
}
});
env.registry.register("serializer:post", BaseSerializer.extend({
attrs: {
description: "description_payload_key"
}
}));

run(function() {
post = env.store.createRecord("post", { title: "Rails is omakase", description: "Omakase is delicious" });
});

var payload = env.container.lookup("serializer:post").serialize(post._createSnapshot());

equal(payload.title_payload_key, "Rails is omakase");
equal(payload.description_payload_key, "Omakase is delicious");
});

test("Serializer should respect the primaryKey attribute when extracting records", function() {
env.registry.register('serializer:post', DS.JSONSerializer.extend({
primaryKey: '_ID_'
Expand Down

0 comments on commit 7d7c55d

Please sign in to comment.