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

Test assertions when updateRecord & deleteRecord don't exist on adapter #4624

Merged
merged 1 commit into from
Oct 26, 2016
Merged
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
46 changes: 40 additions & 6 deletions tests/integration/adapter/store-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ var set = Ember.set;
var run = Ember.run;
var Person, Dog, env, store, adapter;

function moveRecordOutOfInFlight(record) {
run(function() {
// move record out of the inflight state so the tests can clean up
// correctly
Copy link
Member

Choose a reason for hiding this comment

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

@pangratz Do you know why we need to move records out of inflight to make the tests happy?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because of this assertion in the state machine.

let { store, _internalModel } = record;
store.recordWasError(_internalModel, new Error());
});
}

module("integration/adapter/store-adapter - DS.Store and DS.Adapter integration test", {
beforeEach() {
Person = DS.Model.extend({
Expand Down Expand Up @@ -1404,7 +1413,6 @@ test("An async hasMany relationship with links should not trigger shouldBackgrou
}));
});


testInDebug("There should be a friendly error for if the adapter does not implement createRecord", function(assert) {
adapter.createRecord = null;

Expand All @@ -1415,9 +1423,35 @@ testInDebug("There should be a friendly error for if the adapter does not implem
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());
});

moveRecordOutOfInFlight(tom);
});

testInDebug("There should be a friendly error for if the adapter does not implement updateRecord", function(assert) {
adapter.updateRecord = null;

let tom;
assert.expectAssertion(function() {
run(function() {
tom = store.push({ data: { type: 'person', id: 1 } });
tom.save();
});
}, /does not implement 'updateRecord'/);

moveRecordOutOfInFlight(tom);
});

testInDebug("There should be a friendly error for if the adapter does not implement deleteRecord", function(assert) {
adapter.deleteRecord = null;

let tom;
assert.expectAssertion(function() {
run(function() {
tom = store.push({ data: { type: 'person', id: 1 } });
tom.deleteRecord();
tom.save();
});
}, /does not implement 'deleteRecord'/);

moveRecordOutOfInFlight(tom);
});