[Bast-commits] r4698 - in DBIx-Class-Journal/1.000/trunk: lib/DBIx/Class t

nothingmuch at dev.catalyst.perl.org nothingmuch at dev.catalyst.perl.org
Thu Jul 31 17:52:32 BST 2008


Author: nothingmuch
Date: 2008-07-31 17:52:32 +0100 (Thu, 31 Jul 2008)
New Revision: 4698

Modified:
   DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal.pm
   DBIx-Class-Journal/1.000/trunk/t/01test.t
Log:
log for recreated entries

Modified: DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal.pm
===================================================================
--- DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal.pm	2008-07-31 11:15:58 UTC (rev 4697)
+++ DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal.pm	2008-07-31 16:52:32 UTC (rev 4698)
@@ -29,10 +29,18 @@
     {
         my $s_name = $self->result_source->source_name();
         my $al = $self->result_source->schema->_journal_schema->resultset("${s_name}AuditLog");
-        $al->update_or_create({
-            ( map { $_ => $self->get_column($_)} $self->primary_columns ),
-            created => { changeset_id => $al->result_source->schema->current_changeset },
-        });
+
+        my %id = map { $_ => $self->get_column($_)} $self->primary_columns;
+
+        my $change = { changeset_id => $al->result_source->schema->current_changeset };
+
+        if ( my $log = $al->find(\%id) ) {
+            #$log->created($change); # FIXME should this work?
+            $log->created($al->related_resultset("created")->create($change));
+            $log->update;
+        } else {
+            $al->create({ %id, created => $change });
+        }
     }
 
     return $res;

Modified: DBIx-Class-Journal/1.000/trunk/t/01test.t
===================================================================
--- DBIx-Class-Journal/1.000/trunk/t/01test.t	2008-07-31 11:15:58 UTC (rev 4697)
+++ DBIx-Class-Journal/1.000/trunk/t/01test.t	2008-07-31 16:52:32 UTC (rev 4698)
@@ -10,7 +10,7 @@
     eval "use DBD::SQLite";
     plan $@
         ? ( skip_all => 'needs DBD::SQLite for testing' )
-        : ( tests => 16 );
+        : ( tests => 21 );
 }
 
 my $schema = DBICTest->init_schema(no_populate => 1);
@@ -64,13 +64,36 @@
     });
 } );
 
+
+my %id = map { $_ => $new_cd->get_column($_) } $new_cd->primary_columns;
+
 $schema->txn_do( sub {
     $new_cd->delete;
-} );
+});
 
-my $alentry = $search->find({ map { $_ => $new_cd->get_column($_) } $new_cd->primary_columns });
-ok(defined($alentry->deleted), 'Deleted set in audit_log');
+{
+    my $alentry = $search->find(\%id);
+    ok($alentry, "got log entry");
+    ok(defined($alentry->deleted), 'Deleted set in audit_log');
+    cmp_ok( $alentry->deleted->id, ">", $alentry->created->id, "deleted is after created" );
+}
 
+$new_cd = $schema->txn_do( sub {
+    $schema->resultset('CD')->create({
+        %id,
+        title => 'lalala',
+        artist => $artist,
+        year => 2000,
+    });
+});
+
+{
+    my $alentry = $search->find(\%id);
+    ok($alentry, "got log entry");
+    ok(defined($alentry->deleted), 'Deleted set in audit_log');
+    cmp_ok( $alentry->deleted->id, "<", $alentry->created->id, "deleted is before created (recreated)" );
+}
+
 $schema->changeset_user(1);
 $schema->txn_do( sub {
     $schema->resultset('CD')->create({
@@ -78,12 +101,12 @@
         artist => $artist,
         year => 1999,
     });
-} );
+});
 
 ok($search->count > 1, 'Created an second entry in the CD audit history');
 
-my $cset = $schema->_journal_schema->resultset('ChangeSet')->find(5);
-is($cset->user_id, 1, 'Set user id for 5th changeset');
+my $cset = $schema->_journal_schema->resultset('ChangeSet')->find(6);
+is($cset->user_id, 1, 'Set user id for 6th changeset');
 
 $schema->changeset_session(1);
 $schema->txn_do( sub {
@@ -94,6 +117,8 @@
     });
 } );
 
-my $cset2 = $schema->_journal_schema->resultset('ChangeSet')->find(6);
-is($cset2->session_id, 1, 'Set session id for 6th changeset');
+my $cset2 = $schema->_journal_schema->resultset('ChangeSet')->find(7);
+is($cset2->session_id, 1, 'Set session id for 7th changeset');
 
+
+




More information about the Bast-commits mailing list