Skip to content

Commit

Permalink
Check for pendingQueue on willCommit in pending.comitting.
Browse files Browse the repository at this point in the history
  • Loading branch information
caligo-mentis committed Apr 20, 2012
1 parent 8ea2f75 commit 8c03257
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/ember-data/lib/system/model/states.js
Expand Up @@ -494,8 +494,13 @@ var DirtyState = DS.State.extend({
},

willCommit: function(manager) {
var dirtyType = get(this, 'dirtyType');
manager.goToState(dirtyType + '.inFlight');
var record = get(manager, 'record'),
pendingQueue = get(record, 'pendingQueue');

if (isEmptyObject(pendingQueue)) {
var dirtyType = get(this, 'dirtyType');
manager.goToState(dirtyType + '.inFlight');
}
}
})
}),
Expand Down
34 changes: 34 additions & 0 deletions packages/ember-data/tests/unit/model_test.js
Expand Up @@ -351,6 +351,40 @@ test("when a new record depends on the state of another record, it enters the pe
equal(get(childComment, 'isPending'), false, "Child comment is no longer pending on the parent comment");
});

test("when a new record depends on the state of another record which depends on the state of another record, it enters the pending state", function() {
var id = 0;

var store = DS.Store.create({
adapter: DS.Adapter.create({
createRecord: function(store, type, record) {
var hash = record.toJSON();
hash.id = ++id;
store.didCreateRecord(record, hash);
}
})
});
var Comment = DS.Model.extend();

var parentComment = store.createRecord(Comment);
var childComment = store.createRecord(Comment);
var grandchildComment = store.createRecord(Comment);

childComment.waitingOn(parentComment);
grandchildComment.waitingOn(childComment);

equal(get(childComment, 'isPending'), true, "Child comment is pending on the parent comment");
equal(get(grandchildComment, 'isPending'), true, "Grandchild comment is pending on the child comment");

Ember.run(function() {
store.commit();
});

equal(get(parentComment, 'isLoaded'), true, "precond - Parent comment is loaded");
equal(get(parentComment, 'isDirty'), false, "precond - Parent comment is not dirty");
equal(get(childComment, 'isPending'), false, "Child comment is no longer pending on the parent comment");
equal(get(grandchildComment, 'isPending'), false, "Second level comment is on its parent comment");
});

test("when an updated record depends on the state of another record, it enters the pending state", function() {
var id = 0,
parentComment;
Expand Down

0 comments on commit 8c03257

Please sign in to comment.