[Bast-commits] r9266 - in DBIx-Class-Journal/1.000/trunk: . t

oliver at dev.catalyst.perl.org oliver at dev.catalyst.perl.org
Wed Apr 28 20:57:14 GMT 2010


Author: oliver
Date: 2010-04-28 21:57:14 +0100 (Wed, 28 Apr 2010)
New Revision: 9266

Added:
   DBIx-Class-Journal/1.000/trunk/t/03populate.t
Modified:
   DBIx-Class-Journal/1.000/trunk/Changes
Log:
add test (which fail) and update Changelog for prepopulate_journal

Modified: DBIx-Class-Journal/1.000/trunk/Changes
===================================================================
--- DBIx-Class-Journal/1.000/trunk/Changes	2010-04-28 20:05:36 UTC (rev 9265)
+++ DBIx-Class-Journal/1.000/trunk/Changes	2010-04-28 20:57:14 UTC (rev 9266)
@@ -1,3 +1,7 @@
+0.900001_05 2010-04-28
+    - Added prepopulate_journal() to bootstrap insert logs, for retrofitting (oliver)
+    - Added bootstrap_journal() which calls deploy_journal() and then prepopulate_journal() (oliver)
+
 0.900001_04 2010-04-27
     - Lots of documentation tweaks (oliver)
     - Fix a bug caused by storing state of row BEFORE update instead of after (oliver)

Added: DBIx-Class-Journal/1.000/trunk/t/03populate.t
===================================================================
--- DBIx-Class-Journal/1.000/trunk/t/03populate.t	                        (rev 0)
+++ DBIx-Class-Journal/1.000/trunk/t/03populate.t	2010-04-28 20:57:14 UTC (rev 9266)
@@ -0,0 +1,99 @@
+use strict;
+use warnings;
+
+use Test::More;
+BEGIN {
+    eval "use DBD::SQLite; use SQL::Translator";
+    plan $@
+        ? ( skip_all => 'needs DBD::SQLite and SQL::Translator for testing' )
+        : ( tests => 21 );
+}
+
+use lib qw(t/lib);
+use DBICTest;
+
+# connect to db and deploy only the original db schema, not journal schema
+my $schema = DBICTest->init_schema(no_populate => 1, no_deploy => 1);
+$schema->deploy;
+
+ok($schema, 'Created a Schema');
+
+# check we have no journal
+my $count = eval {
+    $schema->_journal_schema->resultset('ChangeLog')->count;
+};
+my $e = $@;
+
+is( $count, undef, 'no count' );
+like( $e, qr/table.*changelog/, 'missing table error' );
+
+# insert two rows -not- in txn
+my ($artistA, $artistB);
+#$schema->txn_do(sub {
+    $artistA = $schema->resultset('Artist')->create({
+        name => 'Fred Bloggs A',
+    });
+
+    $artistB = $schema->resultset('Artist')->create({
+        name => 'Fred Bloggs B',
+    });
+#});
+
+# create the journal
+$schema->journal_schema_deploy();
+
+# check it is empty
+$count = eval { $schema->_journal_schema->resultset('ChangeLog')->count };
+
+is( $@, '', "no error" );
+is( $count, 0, "count is 0 (chagnelog)" );
+
+# run populate
+$schema->prepopulate_journal();
+
+# check there is only one changeset
+$count = eval { $schema->_journal_schema->resultset('ChangeSet')->count };
+
+is( $@, '', "no error" );
+is( $count, 1, "count is 1 (changeset)" );
+
+# check it contains two inserts
+$count = eval { $schema->_journal_schema->resultset('ChangeLog')->count };
+
+is( $@, '', "no error" );
+is( $count, 2, "count is 2 (changelog)" );
+
+# check audit log has two rows for two inserts
+$count = eval { $schema->_journal_schema->resultset('ArtistAuditLog')->count };
+
+is( $@, '', "no error" );
+is( $count, 2, "count is 2 (auditlog)" );
+
+# now delete a row
+eval {
+    my $deleted = $schema->txn_do(sub {
+        $artistA->delete;
+    });
+};
+
+is( $@, '', "no error from deletion journal (create_id not null)" );
+is( $artistA->in_storage, 0, "row was deleted" );
+
+# check journal log still has two rows
+$count = eval { $schema->_journal_schema->resultset('ArtistAuditLog')->count };
+
+is( $@, '', "no error" );
+is( $count, 2, "count is 2 (auditlog 2)" );
+
+# and that one of them has a delete_id
+$count = eval {
+    $schema->_journal_schema->resultset('ArtistAuditLog')
+        ->search({
+            artistid => $artistA->id,
+            delete_id => { '-not' => undef }
+        })->count;
+};
+    
+is( $@, '', "no error" );
+is( $count, 1, "count is 1 (delete_id)" );
+




More information about the Bast-commits mailing list