Skip to content

Commit

Permalink
Add a better error message when findRecord returns an array
Browse files Browse the repository at this point in the history
Closes #3950
  • Loading branch information
bmac committed Nov 30, 2015
1 parent b6242fc commit 110127a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions addon/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function _find(adapter, store, typeClass, id, internalModel, options) {
Ember.assert("You made a `find` request for a " + typeClass.typeClassKey + " with id " + id + ", but the adapter's response did not have any data", payloadIsNotBlank(adapterPayload));
return store._adapterRun(function() {
var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, id, 'findRecord');
Ember.assert('Ember Data expected the primary data returned from a `findRecord` response to be an object but instead it found an array.', !Array.isArray(payload.data));
//TODO Optimize
var record = store.push(payload);
return record._internalModel;
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,17 @@ test("Store should accept a null value for `data`", function(assert) {
});
});
});

test('store#findRecord that returns an array should assert', assert => {
initializeStore(DS.JSONAPIAdapter.extend({
findRecord: function() {
return { data: [] };
}
}));

assert.expectAssertion(function() {
run(function() {
store.findRecord('car', 1);
});
}, /expected the primary data returned from a `findRecord` response to be an object but instead it found an array/);
});

0 comments on commit 110127a

Please sign in to comment.