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

Don't remove records from record arrays before commiting #2867

Closed
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
4 changes: 3 additions & 1 deletion packages/ember-data/lib/system/record_array_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export default Ember.Object.extend({
*/
updateRecordArrays: function() {
forEach(this.changedRecords, function(record) {
if (get(record, 'isDeleted')) {
// TODO: it can be refactored after #2862 && #2859 are closed
if (get(record, 'isDestroyed') || get(record, 'isDestroying') ||
(get(record, 'isDeleted') && !get(record, 'isDirty'))) {
this._recordWasDeleted(record);
} else {
this._recordWasChanged(record);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test("Watching Records", function() {
deepEqual(record.searchKeywords, ['2', 'New Post']);
deepEqual(record.color, 'green');

Ember.run(post, 'deleteRecord');
Ember.run(post, 'unloadRecord');

equal(removedIndex, 1);
equal(removedCount, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,38 @@ module("integration/deletedRecord - Deleting Records", {
}
});

test("records should not be removed from record arrays just after deleting, but only after commiting them", function () {
var adam, dave;

env.adapter.deleteRecord = function() {
return Ember.RSVP.Promise.resolve();
};

run(function() {
adam = env.store.push('person', { id: 1, name: "Adam Sunderland" });
dave = env.store.push('person', { id: 2, name: "Dave Sunderland" });
});
var all = env.store.all('person');

// pre-condition
equal(all.get('length'), 2, 'expected 2 records');

Ember.run(adam, 'deleteRecord');

equal(all.get('length'), 2, 'expected 2 record');

Ember.run(adam, 'save');

equal(all.get('length'), 1, 'expected 1 record');
});

test("records can be deleted during record array enumeration", function () {
var adam, dave;

env.adapter.deleteRecord = function() {
return Ember.RSVP.Promise.resolve();
};

run(function() {
adam = env.store.push('person', { id: 1, name: "Adam Sunderland" });
dave = env.store.push('person', { id: 2, name: "Dave Sunderland" });
Expand All @@ -35,7 +65,7 @@ test("records can be deleted during record array enumeration", function () {

Ember.run(function() {
all.forEach(function(record) {
record.deleteRecord();
record.destroyRecord();
});
});

Expand Down
5 changes: 1 addition & 4 deletions packages/ember-data/tests/unit/model/rollback_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ test("a record's changes can be made if it fails to save", function() {
});

test("a deleted record can be rollbacked if it fails to save, record arrays are updated accordingly", function() {
expect(6);
expect(5);
env.adapter.deleteRecord = function(store, type, record) {
return Ember.RSVP.reject();
};
Expand All @@ -124,7 +124,6 @@ test("a deleted record can be rollbacked if it fails to save, record arrays are
run(function() {
person.deleteRecord();
});
equal(people.get('length'), 0, "a deleted record does not appear in record array anymore");

run(function() {
person.save().then(null, function() {
Expand Down Expand Up @@ -167,8 +166,6 @@ test("deleted record can be rollbacked", function() {
person.deleteRecord();
});

equal(people.get('length'), 0, "a deleted record does not appear in record array anymore");

equal(person.get('isDeleted'), true, "must be deleted");

run(function() {
Expand Down