diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index d31ed510508..844d4fb9684 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -51,6 +51,8 @@ import InternalModel from "ember-data/system/model/internal-model"; import EmptyObject from "ember-data/system/empty-object"; +export let badIdFormatAssertion = '`id` has to be non-empty string or number'; + var Backburner = Ember._Backburner || Ember.Backburner || Ember.__loader.require('backburner')['default'] || Ember.__loader.require('backburner')['Backburner']; var Map = Ember.Map; @@ -495,6 +497,8 @@ Store = Service.extend({ */ findRecord: function(modelName, id, options) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); + Ember.assert(badIdFormatAssertion, (typeof id === 'string' && id.length > 0) || (typeof id === 'number' && !isNaN(id))); + var internalModel = this._internalModelForId(modelName, id); options = options || {}; diff --git a/packages/ember-data/tests/integration/store-test.js b/packages/ember-data/tests/integration/store-test.js index 1f3f8ff69ee..023ecd73f34 100644 --- a/packages/ember-data/tests/integration/store-test.js +++ b/packages/ember-data/tests/integration/store-test.js @@ -211,8 +211,7 @@ function ajaxResponse(value) { -module("integration/store - findRecord", { -}); +module("integration/store - findRecord"); test("store#findRecord fetches record from server when cached record is not present", function() { expect(2); @@ -316,6 +315,21 @@ test("store#findRecord { reload: true } ignores cached record and reloads record }); }); +test('store#findRecord call with `id` of type different than non-empty string or number should trigger an assertion', assert => { + const badValues = ['', undefined, null, NaN, false]; + assert.expect(badValues.length); + + initializeStore(DS.RESTAdapter.extend()); + + run(function() { + badValues.map(item => { + expectAssertion(function() { + store.findRecord('car', item); + }, '`id` has to be non-empty string or number'); + }); + }); +}); + module("integration/store - findAll", { setup: function() { initializeStore(DS.RESTAdapter.extend()); diff --git a/packages/ember-data/tests/unit/model-test.js b/packages/ember-data/tests/unit/model-test.js index 2d67d8faf6e..3a5c8a0ae34 100644 --- a/packages/ember-data/tests/unit/model-test.js +++ b/packages/ember-data/tests/unit/model-test.js @@ -467,7 +467,6 @@ test("currentState is accessible when the record is created", function() { }); }); - module("unit/model - DS.Model updating", { setup: function() { Person = DS.Model.extend({ name: DS.attr('string') });