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

Add error message in _pushInternalMessage when unknown type #3544

Merged
merged 1 commit into from
Jul 14, 2015
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
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
14 changes: 14 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,20 @@ 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({
data: {
id: '1',
type: 'unknown'
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be valid JSON API and has to be wrapped in data:

{
  data: {
    type: 'unknown',
    id: '1'
  }
}

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