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 Dec 11, 2015
1 parent 5794d27 commit efd0e5d
Show file tree
Hide file tree
Showing 2 changed files with 13 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 @@ -190,6 +190,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 tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,18 @@ test("queryRecord - returning an array picks the first one but saves all records
}));
});

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

assert.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(assert) {
env.registry.register('serializer:post', DS.RESTSerializer.extend({
primaryKey: '_ID_',
Expand Down

0 comments on commit efd0e5d

Please sign in to comment.