Skip to content

Commit

Permalink
Merge pull request #4624 from pangratz/add-more-tests-around-assertin…
Browse files Browse the repository at this point in the history
…g-adapter-methods-exist

Test assertions when updateRecord & deleteRecord don't exist on adapter
  • Loading branch information
bmac authored Oct 26, 2016
2 parents ae1d7ae + 8e788d2 commit ef4ed82
Showing 1 changed file with 40 additions and 6 deletions.
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
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);
});

0 comments on commit ef4ed82

Please sign in to comment.