Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better error messaging for adapters that do not implement createR… #4283

Merged
merged 1 commit into from
Oct 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


var promise = _find(adapter, this, typeClass, id, internalModel, options);
return promise;
Expand Down Expand Up @@ -2425,6 +2425,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}`;
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/adapter/store-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand All @@ -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");

}));
});

Expand Down Expand Up @@ -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());
});
});