From 5b8439711a01d29052fd5f805341e06558bd6d88 Mon Sep 17 00:00:00 2001 From: pangratz Date: Tue, 26 Jan 2016 19:18:26 +0100 Subject: [PATCH] [BUGFIX beta] Add assertions for store#query() Currently invoking `store.query('person')` will fail with an error within `RESTAdapter#sortQueryParams`, which is not helpful. This adds the following assertions to store#query(): - a type is passed to the query method - a query hash is passed to the query method --- addon/-private/system/store.js | 2 ++ tests/integration/adapter/queries-test.js | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/addon/-private/system/store.js b/addon/-private/system/store.js index 8711f06fb49..9c53391551b 100644 --- a/addon/-private/system/store.js +++ b/addon/-private/system/store.js @@ -957,6 +957,8 @@ Store = Service.extend({ }, _query(modelName, query, array) { + assert("You need to pass a type to the store's query method", modelName); + assert("You need to pass a query hash to the store's query method", query); assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); array = array || this.recordArrayManager diff --git a/tests/integration/adapter/queries-test.js b/tests/integration/adapter/queries-test.js index 8557997fba8..79e905fde96 100644 --- a/tests/integration/adapter/queries-test.js +++ b/tests/integration/adapter/queries-test.js @@ -28,6 +28,18 @@ module("integration/adapter/queries - Queries", { } }); +test("It raises an assertion when no type is passed", function(assert) { + assert.expectAssertion(function() { + store.query(); + }, "You need to pass a type to the store's query method"); +}); + +test("It raises an assertion when no query hash is passed", function(assert) { + assert.expectAssertion(function() { + store.query('person'); + }, "You need to pass a query hash to the store's query method"); +}); + test("When a query is made, the adapter should receive a record array it can populate with the results of the query.", function(assert) { adapter.query = function(store, type, query, recordArray) { assert.equal(type, Person, "the query method is called with the correct type");