From 242d19870f6e0f4bce447417cd6702c1bd16b4c8 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 2 Mar 2016 18:15:50 +0100 Subject: [PATCH] [BUGFIX release] Fix RESTAdapter.buildQuery without a snapshot Before introducing a feature ds-finder-include it was possible to run findRecord on an adapter without passing a snapshot. After introducing the feature it's no longer possible even if the feature is disabled, because some of the code was outsief of the flag check. This commit fixes the code to work like before introducing the ds-finder-include change. (cherry picked from commit c3b6094bc96c29bbbc0ecd9ea883e7316b4aca0d) --- addon/adapters/rest.js | 10 ++++++---- tests/unit/adapters/rest-adapter/build-query-test.js | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/addon/adapters/rest.js b/addon/adapters/rest.js index bf35d68435b..518960af745 100644 --- a/addon/adapters/rest.js +++ b/addon/adapters/rest.js @@ -992,13 +992,15 @@ export default Adapter.extend(BuildURLMixin, { }, buildQuery(snapshot) { - const { include } = snapshot; - let query = {}; if (isEnabled('ds-finder-include')) { - if (include) { - query.include = include; + if (snapshot) { + const { include } = snapshot; + + if (include) { + query.include = include; + } } } diff --git a/tests/unit/adapters/rest-adapter/build-query-test.js b/tests/unit/adapters/rest-adapter/build-query-test.js index fa098e56c2e..6632346548d 100644 --- a/tests/unit/adapters/rest-adapter/build-query-test.js +++ b/tests/unit/adapters/rest-adapter/build-query-test.js @@ -13,6 +13,13 @@ test("buildQuery() returns an empty query when snapshot has no query params", fu assert.deepEqual(query, {}, 'query is empty'); }); +test("buildQuery - doesn't fail without a snapshot", function(assert) { + const adapter = DS.RESTAdapter.create(); + const query = adapter.buildQuery(); + + assert.deepEqual(query, {}, 'returns an empty query'); +}); + if (isEnabled('ds-finder-include')) { test("buildQuery() returns query with `include` from snapshot", function(assert) { const adapter = DS.RESTAdapter.create();