Permalink
Browse files

Check for pendingQueue on willCommit in pending.comitting.

  • Loading branch information...
1 parent 8ea2f75 commit 8c032573c3359c6cef39e38c42a816f9f5a4f725 @caligo-mentis committed Apr 20, 2012
Showing with 41 additions and 2 deletions.
  1. +7 −2 packages/ember-data/lib/system/model/states.js
  2. +34 −0 packages/ember-data/tests/unit/model_test.js
View
9 packages/ember-data/lib/system/model/states.js
@@ -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');
+ }
}
})
}),
View
34 packages/ember-data/tests/unit/model_test.js
@@ -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;

0 comments on commit 8c03257

Please sign in to comment.