Permalink
Browse files

Merge pull request #238 from tchak/invalid-rollback-fix

fix for inflight bucket
  • Loading branch information...
tomdale committed May 3, 2012
2 parents cc62180 + fb506a2 commit 3a94ddd27943f3159afc4a9c8fd94d034d167010
@@ -352,6 +352,17 @@ var DirtyState = DS.State.extend({
manager.goToState('inFlight');
},
+ becameInvalid: function(manager) {
+ var dirtyType = get(this, 'dirtyType'),
+ record = get(manager, 'record');
+
+ record.withTransaction(function (t) {
+ t.recordBecameInFlight(dirtyType, record);
+ });
+
+ manager.goToState('invalid');
+ },
+
rollback: function(manager) {
var record = get(manager, 'record'),
dirtyType = get(this, 'dirtyType'),
@@ -386,7 +397,12 @@ var DirtyState = DS.State.extend({
// EVENTS
didCommit: function(manager) {
- var dirtyType = get(this, 'dirtyType');
+ var dirtyType = get(this, 'dirtyType'),
+ record = get(manager, 'record');
+
+ record.withTransaction(function(t) {
+ t.recordBecameClean('inflight', record);
+ });
manager.goToState('loaded');
manager.send('invokeLifecycleCallbacks', dirtyType);
@@ -676,14 +692,6 @@ var states = {
// in the `saved` state.
saved: DS.State.create({
- enter: function(manager) {
- var record = get(manager, 'record');
-
- record.withTransaction(function(t) {
- t.recordBecameClean('inflight', record);
- });
- },
-
// EVENTS
setProperty: function(manager, context) {
setProperty(manager, context);
@@ -783,16 +791,22 @@ var states = {
isSaving: true,
// TRANSITIONS
- exit: function(stateManager) {
- var record = get(stateManager, 'record');
+ enter: function(manager) {
+ var record = get(manager, 'record');
- record.withTransaction(function(t) {
- t.recordBecameClean('deleted', record);
+ record.withTransaction(function (t) {
+ t.recordBecameInFlight('deleted', record);
});
},
// EVENTS
didCommit: function(manager) {
+ var record = get(manager, 'record');
+
+ record.withTransaction(function(t) {
+ t.recordBecameClean('inflight', record);
+ });
+
manager.goToState('saved');
manager.send('invokeLifecycleCallbacks');
@@ -329,9 +329,7 @@ DS.Transaction = Ember.Object.extend({
type = record.constructor;
var records = bucket.get(type);
- if (records) {
- records.remove(record);
- }
+ records.remove(record);
},
/**
@@ -290,3 +290,23 @@ test("modified records are reset when their transaction is rolled back", functio
equal(get(invalidPerson, 'transaction'), get(store, 'defaultTransaction'), "record should have been moved back to the default transaction");
});
+test("modified records are reset when their transaction is rolled back", function() {
+ var store = DS.Store.create();
+
+ store.load(Person, { id: 1, name: "Scumbag Tom" });
+
+ var person = store.find(Person, 1);
+
+ var transaction = store.transaction();
+ transaction.add(person);
+
+ person.set('name', 'toto');
+
+ store.recordWasInvalid(person, {name: 'error'});
+
+ equal(person.get('isValid'), false, "precond - invalid record is marked as invalid");
+
+ transaction.rollback();
+
+ equal(person.get('isValid'), true, "invalid record is now marked as valid");
+});

0 comments on commit 3a94ddd

Please sign in to comment.