Skip to content

Commit

Permalink
Consistent cleanup of updateRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdivad committed Mar 1, 2017
1 parent e527d2f commit a0bab0b
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,11 @@ if (isEnabled('ds-rollback-attribute')) {
test('Using rollbackAttribute on an in-flight record reverts to the latest in-flight value', function(assert) {
assert.expect(4);

let person, finishSaving;
let updateRecordPromise = new Ember.RSVP.Promise(resolve => finishSaving = resolve);
let person;

// Make sure the save is async
env.adapter.updateRecord = function(store, type, snapshot) {
return updateRecordPromise;
return Ember.RSVP.resolve();
};

return run(() => {
Expand All @@ -552,21 +551,18 @@ if (isEnabled('ds-rollback-attribute')) {
person.rollbackAttribute('name');
assert.equal(person.get('name'), 'Thomas');

finishSaving();

return saving;
});
});

test('Saving an in-flight record updates the in-flight value rollbackAttribute will use', function(assert) {
assert.expect(7);

let person, finishSaving;
let updateRecordPromise = new Ember.RSVP.Promise(resolve => finishSaving = resolve);
let person

// Make sure the save is async
env.adapter.updateRecord = function(store, type, snapshot) {
return updateRecordPromise;
return Ember.RSVP.resolve();
};

run(() => {
Expand Down Expand Up @@ -600,7 +596,7 @@ if (isEnabled('ds-rollback-attribute')) {
saving.push(person.save());
});

run(() => {
return run(() => {
assert.equal(person.get('isSaving'), true);
assert.equal(person.get('name'), "Tomathy");

Expand All @@ -610,10 +606,8 @@ if (isEnabled('ds-rollback-attribute')) {
person.rollbackAttribute('name');
assert.equal(person.get('name'), 'Tomathy');

finishSaving();
return Ember.RSVP.Promise.all(saving);
});

return Ember.RSVP.Promise.all(saving);
});
}

Expand Down

0 comments on commit a0bab0b

Please sign in to comment.