Passes tests again!
Jess Robinson [Tue, 31 Jul 2007 23:28:55 +0000 (23:28 +0000)]
Bugfix in DBIx::Class::Schema::Journal::txn_do, for cases where all insert values are empty, bugfix needed in dbic really.. ;)

lib/DBIx/Class/Schema/Journal.pm
t/lib/DBICTest.pm

index 21a4815..daeb8c8 100644 (file)
@@ -37,7 +37,7 @@ sub exception_action
 sub connection
 {
     my $self = shift;
-    $self->next::method(@_);
+    my $schema = $self->next::method(@_);
 
 #   print STDERR join(":", $self->sources), "\n";
 
@@ -82,6 +82,8 @@ sub connection
     $self->_journal_schema->deploy();
     $self->_journal_schema->class('ChangeSet')->belongs_to('user', @{$self->journal_user});
     $self->_journal_schema->storage->disconnect();
+
+    return $schema;
 }
 
 sub get_audit_log_class_name
@@ -128,10 +130,13 @@ sub txn_do
     my $cs = $self->_journal_schema->resultset('ChangeSet');
 
     $self->txn_begin;
-    my $changeset = $cs->create({ ( $self->_journal_schema->current_user() ? ( user_id => $self->_journal_schema->current_user()) : () ),
-#        user_id => $self->_journal_schema->current_user(),
-        session_id => $self->_journal_schema->current_session(),
-    });
+    my %changesetdata = ( $self->_journal_schema->current_user() ? ( 'user_id', $self->_journal_schema->current_user()) : () ),
+    ( $self->_journal_schema->current_session() ? ( session_id => $self->_journal_schema->current_session() ) : () );
+    if(!%changesetdata)
+    {
+        %changesetdata = ( ID => undef );
+    }
+    my $changeset = $cs->create({ %changesetdata });
     $self->_journal_schema->current_changeset($changeset->ID);
 
     $self->next::method($code);
index bd6725a..2945da9 100644 (file)
@@ -58,7 +58,19 @@ sub init_schema {
     my $dbuser = $ENV{"DBICTEST_DBUSER"} || '';
     my $dbpass = $ENV{"DBICTEST_DBPASS"} || '';
 
-    my $schema = DBICTest::Schema->compose_connection('DBICTest' => $dsn, $dbuser, $dbpass);
+    my $schema;
+    my @connect_info = ($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
+
+    if ($args{compose_connection}) {
+      $schema = DBICTest::Schema->compose_connection(
+                  'DBICTest', @connect_info
+                );
+    } else {
+      $schema = DBICTest::Schema->compose_namespace('DBICTest')
+                                ->connect(@connect_info);
+    print STDERR "Created Schema: ", ref($schema), "\n";
+    }
+#    my $schema = DBICTest::Schema->compose_connection('DBICTest' => $dsn, $dbuser, $dbpass);
 #    $schema->storage->on_connect_do(['PRAGMA synchronous = OFF']);
     if ( !$args{no_deploy} ) {
         __PACKAGE__->deploy_schema( $schema );
@@ -83,15 +95,15 @@ sub deploy_schema {
     my $self = shift;
     my $schema = shift;
 
-    if ($ENV{"DBICTEST_SQLT_DEPLOY"}) {
+#    if ($ENV{"DBICTEST_SQLT_DEPLOY"}) {
         return $schema->deploy();
-    } else {
-        open IN, "t/lib/sqlite.sql";
-        my $sql;
-        { local $/ = undef; $sql = <IN>; }
-        close IN;
-        ($schema->storage->dbh->do($_) || print "Error on SQL: $_\n") for split(/;\n/, $sql);
-    }
+#     } else {
+#         open IN, "t/lib/sqlite.sql";
+#         my $sql;
+#         { local $/ = undef; $sql = <IN>; }
+#         close IN;
+#         ($schema->storage->dbh->do($_) || print "Error on SQL: $_\n") for split(/;\n/, $sql);
+#     }
 }
 
 =head2 populate_schema