Skip to content

Commit

Permalink
Add error message in _pushInternalMessage when unknown type
Browse files Browse the repository at this point in the history
When pushing data with an unknown type, an error is raised.
Fix #3542
  • Loading branch information
Serabe committed Jul 13, 2015
1 parent d367458 commit 5eda123
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1702,10 +1702,15 @@ Store = Service.extend({
return internalModel.getRecord();
},

_hasModelFor: function(type) {
return this.container.lookupFactory(`model:${type}`);
},

_pushInternalModel: function(data) {
var modelName = data.type;
Ember.assert(`Expected an object as 'data' in a call to 'push' for ${modelName}, but was ${Ember.typeOf(data)}`, Ember.typeOf(data) === 'object');
Ember.assert(`You must include an 'id' for ${modelName} in an object passed to 'push'`, data.id != null && data.id !== '');
Ember.assert(`You tried to push data with a type '${modelName}' but no model could be found with that name.`, this._hasModelFor(modelName));

var type = this.modelFor(modelName);

Expand Down
12 changes: 12 additions & 0 deletions packages/ember-data/tests/unit/store/push-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,18 @@ test('Calling push with a link for a non async relationship should warn', functi
}, /You have pushed a record of type 'person' with 'phoneNumbers' as a link, but the association is not an async relationship./);
});

test('Calling push with an unknown model name throws an assertion error', function() {

expectAssertion(function() {
run(function() {
store.push({
id: '1',
type: 'unknown'
});
});
}, /You tried to push data with a type 'unknown' but no model could be found with that name/);
});

test('Calling push with a link containing an object throws an assertion error', function() {
Person.reopen({
phoneNumbers: hasMany('phone-number', { async: true })
Expand Down

0 comments on commit 5eda123

Please sign in to comment.