Skip to content

Commit

Permalink
Merge pull request #3859 from tchak/handle-invlid-errors-without-payload
Browse files Browse the repository at this point in the history
[BUGFIX beta] Correctly handle invalid errors without payload or pointer
  • Loading branch information
tchak committed Oct 15, 2015
2 parents af4c323 + f4e7100 commit f545e98
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/ember-data/lib/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ InternalModel.prototype = {
}
}

this.send('becameInvalid');

this._saveWasRejected();
},

Expand Down
5 changes: 3 additions & 2 deletions packages/ember-data/lib/system/model/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ var DirtyState = {
didSetProperty(internalModel, context);
},

becameInvalid: Ember.K,
becomeDirty: Ember.K,

pushedData: Ember.K,

willCommit: function(internalModel) {
Expand Down Expand Up @@ -702,8 +702,9 @@ var RootState = {
didSetProperty(internalModel, context);
},

deleteRecord: Ember.K,
becameInvalid: Ember.K,
becomeDirty: Ember.K,
deleteRecord: Ember.K,
willCommit: Ember.K,


Expand Down
59 changes: 58 additions & 1 deletion packages/ember-data/tests/integration/records/save-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ test("Retry is allowed in a failure handler", function() {
});

test("Repeated failed saves keeps the record in uncommited state", function() {
expect(2);
expect(4);
var post;

run(function() {
Expand All @@ -100,15 +100,72 @@ test("Repeated failed saves keeps the record in uncommited state", function() {

run(function() {
post.save().then(null, function() {
ok(post.get('isError'));
equal(post.get('currentState.stateName'), 'root.loaded.created.uncommitted');

post.save().then(null, function() {
ok(post.get('isError'));
equal(post.get('currentState.stateName'), 'root.loaded.created.uncommitted');
});
});
});
});

test("Repeated failed saves with invalid error marks the record as invalid", function() {
expect(2);
var post;

run(function() {
post = env.store.createRecord('post', { title: 'toto' });
});

env.adapter.createRecord = function(store, type, snapshot) {
var error = new DS.InvalidError([
{
detail: 'is invalid',
source: { pointer: 'data/attributes/title' }
}
]);

return Ember.RSVP.reject(error);
};

run(function() {
post.save().then(null, function() {
equal(post.get('isValid'), false);

post.save().then(null, function() {
equal(post.get('isValid'), false);
});
});
});
});

test("Repeated failed saves with invalid error without payload marks the record as invalid", function() {
expect(2);
var post;

run(function() {
post = env.store.createRecord('post', { title: 'toto' });
});

env.adapter.createRecord = function(store, type, snapshot) {
var error = new DS.InvalidError();

return Ember.RSVP.reject(error);
};

run(function() {
post.save().then(null, function() {
equal(post.get('isValid'), false);

post.save().then(null, function() {
equal(post.get('isValid'), false);
});
});
});
});

test("Will reject save on invalid", function() {
expect(1);
var post;
Expand Down

0 comments on commit f545e98

Please sign in to comment.