diff --git a/addon/-private/system/store.js b/addon/-private/system/store.js index e30e25bc857..fe862e628d6 100644 --- a/addon/-private/system/store.js +++ b/addon/-private/system/store.js @@ -749,7 +749,7 @@ Store = Service.extend({ var adapter = this.adapterFor(typeClass.modelName); assert("You tried to find a record but you have no adapter (for " + typeClass + ")", adapter); - assert("You tried to find a record but your adapter (for " + typeClass + ") does not implement 'findRecord'", typeof adapter.findRecord === 'function' || typeof adapter.find === 'function'); + assert("You tried to find a record but your adapter (for " + typeClass + ") does not implement 'findRecord'", typeof adapter.findRecord === 'function'); var promise = _find(adapter, this, typeClass, id, internalModel, options); return promise; @@ -2597,6 +2597,8 @@ function _commit(adapter, store, operation, snapshot) { var internalModel = snapshot._internalModel; var modelName = snapshot.modelName; var typeClass = store.modelFor(modelName); + assert(`You tried to update a record but you have no adapter (for ${typeClass})`, adapter); + assert(`You tried to update a record but your adapter (for ${typeClass}) does not implement '${operation}'`, typeof adapter[operation] === 'function'); var promise = adapter[operation](store, typeClass, snapshot); var serializer = serializerForAdapter(store, adapter, modelName); var label = `DS: Extract and notify about ${operation} completion of ${internalModel}`; diff --git a/tests/integration/adapter/store-adapter-test.js b/tests/integration/adapter/store-adapter-test.js index 0094d5a7bdd..8048750aad0 100644 --- a/tests/integration/adapter/store-adapter-test.js +++ b/tests/integration/adapter/store-adapter-test.js @@ -2,6 +2,7 @@ import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import {module, test} from 'qunit'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; import DS from 'ember-data'; @@ -108,6 +109,7 @@ test("by default, createRecords calls createRecord once per record", function(as yehuda: yehuda.save() }); }); + promise.then(assert.wait(function(records) { tom = records.tom; yehuda = records.yehuda; @@ -116,6 +118,7 @@ test("by default, createRecords calls createRecord once per record", function(as assert.asyncEqual(yehuda, store.findRecord('person', 2), "Once an ID is in, findRecord returns the same object"); assert.equal(get(tom, 'updatedAt'), "now", "The new information is received"); assert.equal(get(yehuda, 'updatedAt'), "now", "The new information is received"); + })); }); @@ -1400,3 +1403,21 @@ test("An async hasMany relationship with links should not trigger shouldBackgrou assert.equal(comments.get('length'), 3); })); }); + + +testInDebug("There should be a friendly error for if the adapter does not implement createRecord", function(assert) { + adapter.createRecord = null; + + let tom; + assert.expectAssertion(function() { + run(function() { + tom = store.createRecord('person', { name: "Tom Dale" }); + tom.save(); + }); + }, /does not implement 'createRecord'/); + run(function() { + // move record out of the inflight state so the tests can clean up + // correctly + store.recordWasError(tom._internalModel, new Error()); + }); +});