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] Correctly handle invalid errors without payload or pointer #3859

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
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