Skip to content

Commit

Permalink
Throw a more helpful error message if the response from queryRecord i…
Browse files Browse the repository at this point in the history
…s empty
  • Loading branch information
bmac committed Oct 16, 2015
1 parent 921e8c9 commit 9b247d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/ember-data/lib/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export function _queryRecord(adapter, store, typeClass, query) {
var record;
store._adapterRun(function() {
var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, null, 'queryRecord');
Ember.assert('`store.queryRecord` expected the adapter to return one record but the response from the adapter was empty.', payload.data);
//TODO Optimize
record = store.push(payload);
});
Expand Down
12 changes: 12 additions & 0 deletions packages/ember-data/tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,18 @@ test("queryRecord - returning an array picks the first one but saves all records
}));
});

test("queryRecord - returning an empty array errors", function() {
ajaxResponse({
post: []
});

expectAssertion(function() {
Ember.run(function() {
store.queryRecord('post', { slug: 'rails-is-omakaze' });
});
}, /`store.queryRecord` expected the adapter to return one record/);
});

test("queryRecord - data is normalized through custom serializers", function() {
env.registry.register('serializer:post', DS.RESTSerializer.extend({
primaryKey: '_ID_',
Expand Down

0 comments on commit 9b247d2

Please sign in to comment.