Skip to content

Commit

Permalink
Warn when the JSONAPISerializer is extended with the EmbeddedRecordsM…
Browse files Browse the repository at this point in the history
…ixin
  • Loading branch information
bmac committed Mar 23, 2016
1 parent e844222 commit ad4a208
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion addon/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,6 @@ export default Ember.Mixin.create({
let serializer = store.serializerFor(modelName);

return serializer.normalize(modelClass, relationshipHash, null);
}
},
isEmbeddedRecordsMixin: true
});
5 changes: 5 additions & 0 deletions addon/serializers/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,11 @@ const JSONAPISerializer = JSONSerializer.extend({

runInDebug(function() {
JSONAPISerializer.reopen({
willMergeMixin(props) {
warn('The JSONAPISerializer does not work with the EmbeddedRecordsMixin because the JSON API spec does not describe how to format embedded resources.', !props.isEmbeddedRecordsMixin, {
id: 'ds.serializer.embedded-records-mixin-not-supported'
});
},
warnMessageForUndefinedType() {
return 'Encountered a resource object with an undefined type (resolved resource using ' + this.constructor.toString() + ')';
},
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/serializers/json-api-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,10 @@ test('Serializer should respect the attrs hash when serializing attributes with

assert.equal(payload.data.attributes['company_name'], 'Tilde Inc.');
});


test('JSON warns when combined with EmbeddedRecordsMixin', function(assert) {
assert.expectWarning(function() {
DS.JSONAPISerializer.extend(DS.EmbeddedRecordsMixin).create();
}, /The JSONAPISerializer does not work with the EmbeddedRecordsMixin/);
});

0 comments on commit ad4a208

Please sign in to comment.