Skip to content

Commit

Permalink
Merge pull request #3208 from bmac/push-invalid-record
Browse files Browse the repository at this point in the history
DirtyState.invalid handle pushedData event
  • Loading branch information
igorT committed Jun 5, 2015
2 parents 0c5a3a3 + a5e4df6 commit 1e0229c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/ember-data/lib/system/model/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ var DirtyState = {

becomeDirty: Ember.K,

pushedData: Ember.K,

willCommit: function(internalModel) {
internalModel.getErrors().clear();
internalModel.transitionTo('inFlight');
Expand Down
28 changes: 28 additions & 0 deletions packages/ember-data/tests/unit/model/merge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,34 @@ test("When a record is dirty, pushes are overridden by local changes", function(
equal(person.get('city'), "Portland", "if there are no local changes, the new data applied");
});

test("When a record is invalid, pushes are overridden by local changes", function() {
var store = createStore({
adapter: DS.Adapter,
person: Person
});
var person;

run(function() {
person = store.push('person', { id: 1, name: "Brendan McLoughlin", city: "Boston" });
person.set('name', "Brondan McLoughlin");
person.send('becameInvalid');
});

equal(person.get('isDirty'), true, "the person is currently dirty");
equal(person.get('isValid'), false, "the person is currently invalid");
equal(person.get('name'), "Brondan McLoughlin", "the update was effective");
equal(person.get('city'), "Boston", "the original data applies");

run(function() {
store.push('person', { id: 1, name: "bmac", city: "Prague" });
});

equal(person.get('isDirty'), true, "the local changes are reapplied");
equal(person.get('isValid'), false, "record is still invalid");
equal(person.get('name'), "Brondan McLoughlin", "the local changes are reapplied");
equal(person.get('city'), "Prague", "if there are no local changes, the new data applied");
});

test("A record with no changes can still be saved", function() {
expect(1);

Expand Down

0 comments on commit 1e0229c

Please sign in to comment.