Skip to content

Commit

Permalink
Merge pull request #3861 from bmac/issue-3466
Browse files Browse the repository at this point in the history
[BUGFIX beta] Assert that an array is returned from the normalized re…
  • Loading branch information
bmac committed Oct 16, 2015
2 parents 8d0272a + 8a312c6 commit 3e6d6a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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 @@ -155,6 +155,7 @@ export function _query(adapter, store, typeClass, query, recordArray) {
records = store.push(payload);
});

Ember.assert('The response to store.query is expected to be an array but it was a single record. Please wrap your response in an array or use `store.queryRecord` to query for a single record.', Ember.isArray(records));
recordArray.loadRecords(records);
return recordArray;

Expand Down
20 changes: 19 additions & 1 deletion packages/ember-data/tests/integration/adapter/queries-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module("integration/adapter/queries - Queries", {

test("When a query is made, the adapter should receive a record array it can populate with the results of the query.", function() {
adapter.query = function(store, type, query, recordArray) {
equal(type, Person, "the find method is called with the correct type");
equal(type, Person, "the query method is called with the correct type");

return Ember.RSVP.resolve([{ id: 1, name: "Peter Wagenet" }, { id: 2, name: "Brohuda Katz" }]);
};
Expand All @@ -36,3 +36,21 @@ test("When a query is made, the adapter should receive a record array it can pop
equal(queryResults.objectAt(1).get('name'), "Brohuda Katz", "the second record is 'Brohuda Katz'");
}));
});

test("The store asserts when query is made and the adapter responses with a single record.", function() {
env = setupStore({ person: Person, adapter: DS.RESTAdapter });
store = env.store;
adapter = env.adapter;

adapter.query = function(store, type, query, recordArray) {
equal(type, Person, "the query method is called with the correct type");

return Ember.RSVP.resolve({ people: { id: 1, name: "Peter Wagenet" } });
};

expectAssertion(function() {
Ember.run(function() {
store.query('person', { page: 1 });
});
}, /The response to store.query is expected to be an array but it was a single record/);
});

0 comments on commit 3e6d6a9

Please sign in to comment.