From fb48483cccb28a6a8615d7d02efee491fc8b1a6a Mon Sep 17 00:00:00 2001 From: Dan Schultz Date: Sat, 24 Mar 2012 01:20:48 -0700 Subject: [PATCH] Update persistence tests --- tests/mesh/model/RecordCommitTests.as | 29 +++++++++-- tests/mesh/model/RecordPersistenceTests.as | 59 ---------------------- 2 files changed, 25 insertions(+), 63 deletions(-) delete mode 100644 tests/mesh/model/RecordPersistenceTests.as diff --git a/tests/mesh/model/RecordCommitTests.as b/tests/mesh/model/RecordCommitTests.as index 17387d3..5d294fd 100644 --- a/tests/mesh/model/RecordCommitTests.as +++ b/tests/mesh/model/RecordCommitTests.as @@ -38,10 +38,10 @@ package mesh.model _store = new Store(_dataSources); } - private function assertIsSynced(record:Record):void + private function assertIsSynced(record:Record, isRemote:Boolean):void { assertThat(ID.isPopulated(record), equalTo(true)); - assertThat(record.state.isRemote, equalTo(true)); + assertThat(record.state.isRemote, equalTo(isRemote)); assertThat(record.state.isSynced, equalTo(true)); } @@ -50,7 +50,7 @@ package mesh.model { var test:AsyncTest = new AsyncTest(this, LATENCY+100, function():void { - assertIsSynced(customer); + assertIsSynced(customer, true); }); var customer:Customer = _store.create(Customer); @@ -62,12 +62,33 @@ package mesh.model assertThat(customer.state.isBusy, equalTo(true)); } + [Test(async)] + public function testDestroy():void + { + var test:AsyncTest = new AsyncTest(this, LATENCY+(200*2), function():void + { + assertIsSynced(customer, false); + }); + + var customer:Customer = _store.query(Customer).find(1); + customer.loadOperation.addEventListener(FinishedOperationEvent.FINISHED, function(event:FinishedOperationEvent):void + { + customer.destroy().persist(new CommitResponder(function():void + { + test.complete(); + })); + + assertThat(customer.state.isBusy, equalTo(true)); + }); + customer.load(); + } + [Test(async)] public function testUpdate():void { var test:AsyncTest = new AsyncTest(this, LATENCY+(200*2), function():void { - assertIsSynced(customer); + assertIsSynced(customer, true); }); var customer:Customer = _store.query(Customer).find(1); diff --git a/tests/mesh/model/RecordPersistenceTests.as b/tests/mesh/model/RecordPersistenceTests.as deleted file mode 100644 index dfccd49..0000000 --- a/tests/mesh/model/RecordPersistenceTests.as +++ /dev/null @@ -1,59 +0,0 @@ -package mesh.model -{ - import mesh.Customer; - import mesh.Name; - import mesh.Order; - import mesh.model.source.FixtureDataSource; - import mesh.model.source.MultiDataSource; - import mesh.model.store.Store; - - import org.flexunit.assertThat; - import org.hamcrest.object.equalTo; - - public class RecordPersistenceTests - { - private var _store:Store; - private var _customers:FixtureDataSource; - private var _orders:FixtureDataSource; - - [Before] - public function setup():void - { - _customers = new FixtureDataSource(Customer); - _customers.add({id:1, firstName:"Jimmy", lastName:"Page", accountId:1}); - - _orders = new FixtureDataSource(Order); - _orders.add({id:1, customerId:1}); - _orders.add({id:2, customerId:1}); - _orders.add({id:3, customerId:1}); - - var dataSources:MultiDataSource = new MultiDataSource(); - dataSources.map(Customer, _customers); - dataSources.map(Order, _orders); - - _store = new Store(dataSources); - } - - [Test] - public function testCreate():void - { - var customer:Customer = _store.create(Customer); - customer.persist(); - - assertThat(ID.isPopulated(customer), equalTo(true)); - assertThat(customer.state.isRemote, equalTo(true)); - assertThat(customer.state.isSynced, equalTo(true)); - } - - [Test] - public function testUpdate():void - { - var customer:Customer = _store.query(Customer).find(1).load(); - customer.name = new Name("Steve", "Jobs"); - customer.persist(); - - assertThat(customer.state.isRemote, equalTo(true)); - assertThat(customer.state.isSynced, equalTo(true)); - } - } -} \ No newline at end of file