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 beta] rollbackAttributes() works after multiple failed saves #3857

Merged
merged 1 commit into from
Oct 15, 2015
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
5 changes: 0 additions & 5 deletions packages/ember-data/lib/system/model/states.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
@module ember-data
*/
import EmptyObject from "ember-data/system/empty-object";
var get = Ember.get;
/*
This file encapsulates the various states that a record can transition
Expand Down Expand Up @@ -347,10 +346,6 @@ var DirtyState = {

invokeLifecycleCallbacks: function(internalModel) {
internalModel.triggerLater('becameInvalid', internalModel);
},

exit: function(internalModel) {
internalModel._inFlightAttributes = new EmptyObject();
}
}
};
Expand Down
43 changes: 43 additions & 0 deletions packages/ember-data/tests/unit/model/rollback-attributes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,49 @@ test("invalid new record's attributes can be rollbacked", function() {
});
});

test("invalid record's attributes can be rollbacked after multiple failed calls - #3677", function() {
var person;

var adapter = DS.RESTAdapter.extend({
ajax: function(url, type, hash) {
var error = new DS.InvalidError();
return Ember.RSVP.reject(error);
}
});

env = setupStore({ person: Person, adapter: adapter });

run(function() {
person = env.store.push({
data: {
type: 'person',
id: 1,
attributes: {
firstName: 'original name'
}
}
});

person.set('firstName', 'updated name');
});

run(function() {
equal(person.get('firstName'), 'updated name', "precondition: firstName is changed");

person.save().then(null, async(function() {
equal(person.get('hasDirtyAttributes'), true, "has dirty attributes");
equal(person.get('firstName'), 'updated name', "firstName is still changed");

return person.save();
})).then(null, async(function() {
person.rollbackAttributes();

equal(person.get('hasDirtyAttributes'), false, "has no dirty attributes");
equal(person.get('firstName'), 'original name', "after rollbackAttributes() firstName has the original value");
}));
});
});

test("deleted record's attributes can be rollbacked", function() {
var person, people;

Expand Down