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

[BUGFIX] Fix flushing of pending saves, that include a deleted record #4994

Merged
merged 1 commit into from
Jun 18, 2017
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
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);
});