Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Check for pendingQueue on willCommit in pending.comitting.

  • Loading branch information...
commit 8c032573c3359c6cef39e38c42a816f9f5a4f725 1 parent 8ea2f75
Andrey Ivashchenko authored
9 packages/ember-data/lib/system/model/states.js
@@ -494,8 +494,13 @@ var DirtyState = DS.State.extend({
494 494 },
495 495
496 496 willCommit: function(manager) {
497   - var dirtyType = get(this, 'dirtyType');
498   - manager.goToState(dirtyType + '.inFlight');
  497 + var record = get(manager, 'record'),
  498 + pendingQueue = get(record, 'pendingQueue');
  499 +
  500 + if (isEmptyObject(pendingQueue)) {
  501 + var dirtyType = get(this, 'dirtyType');
  502 + manager.goToState(dirtyType + '.inFlight');
  503 + }
499 504 }
500 505 })
501 506 }),
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
351 351 equal(get(childComment, 'isPending'), false, "Child comment is no longer pending on the parent comment");
352 352 });
353 353
  354 +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() {
  355 + var id = 0;
  356 +
  357 + var store = DS.Store.create({
  358 + adapter: DS.Adapter.create({
  359 + createRecord: function(store, type, record) {
  360 + var hash = record.toJSON();
  361 + hash.id = ++id;
  362 + store.didCreateRecord(record, hash);
  363 + }
  364 + })
  365 + });
  366 + var Comment = DS.Model.extend();
  367 +
  368 + var parentComment = store.createRecord(Comment);
  369 + var childComment = store.createRecord(Comment);
  370 + var grandchildComment = store.createRecord(Comment);
  371 +
  372 + childComment.waitingOn(parentComment);
  373 + grandchildComment.waitingOn(childComment);
  374 +
  375 + equal(get(childComment, 'isPending'), true, "Child comment is pending on the parent comment");
  376 + equal(get(grandchildComment, 'isPending'), true, "Grandchild comment is pending on the child comment");
  377 +
  378 + Ember.run(function() {
  379 + store.commit();
  380 + });
  381 +
  382 + equal(get(parentComment, 'isLoaded'), true, "precond - Parent comment is loaded");
  383 + equal(get(parentComment, 'isDirty'), false, "precond - Parent comment is not dirty");
  384 + equal(get(childComment, 'isPending'), false, "Child comment is no longer pending on the parent comment");
  385 + equal(get(grandchildComment, 'isPending'), false, "Second level comment is on its parent comment");
  386 +});
  387 +
354 388 test("when an updated record depends on the state of another record, it enters the pending state", function() {
355 389 var id = 0,
356 390 parentComment;

0 comments on commit 8c03257

Please sign in to comment.
Something went wrong with that request. Please try again.