Skip to content

Commit

Permalink
[BUGFIX beta] Fix flushing of pending saves, that include a deleted r…
Browse files Browse the repository at this point in the history
…ecord

Fixes emberjs#4993
  • Loading branch information
simonihmig committed May 27, 2017
1 parent 58bd396 commit f1f9723
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,8 @@ Store = Service.extend({
let operation;

if (internalModel.currentState.stateName === 'root.deleted.saved') {
return resolver.resolve();
resolver.resolve();
continue;
} else if (internalModel.isNew()) {
operation = 'createRecord';
} else if (internalModel.isDeleted()) {
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/records/delete-record-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,29 @@ test("Destroying an invalid newly created record should remove it from the store
assert.equal(get(record, 'currentState.stateName'), 'root.deleted.saved');
assert.equal(get(store.peekAll('person'), 'length'), 0, 'The new person should be removed from the store');
});

test("Will resolve destroy and save in same loop", function(assert) {
let adam, dave;
let promises;

assert.expect(1);

env.adapter.createRecord = function() {
assert.ok(true, 'save operation resolves');
return Ember.RSVP.Promise.resolve({ id: 123 });
};

run(function() {
adam = env.store.createRecord('person', { name: 'Adam Sunderland' });
dave = env.store.createRecord('person', { name: 'Dave Sunderland' });
});

run(function() {
promises = [
adam.destroyRecord(),
dave.save()
];
});

return Ember.RSVP.all(promises);
});

0 comments on commit f1f9723

Please sign in to comment.