test fixin
[dbsrgits/DBIx-Class-Fixtures.git] / t / lib / DBICTest.pm
index 2e1ddc4..08c0e27 100755 (executable)
@@ -48,9 +48,11 @@ sub init_schema {
 
     my $db_file = "t/var/DBIxClass.db";
 
-    unlink($db_file) if -e $db_file;
-    unlink($db_file . "-journal") if -e $db_file . "-journal";
     mkdir("t/var") unless -d "t/var";
+    if ( !$args{no_deploy} ) {
+      unlink($db_file) if -e $db_file;
+      unlink($db_file . "-journal") if -e $db_file . "-journal";
+    }
 
     my $dsn = $args{"dsn"} || "dbi:SQLite:${db_file}";
     my $dbuser = $args{"user"} || '';
@@ -94,13 +96,21 @@ sub deploy_schema {
     my $self = shift;
     my $schema = shift;
 
-
-    my $file = $self->get_ddl_file($schema);
-    open IN, $file;
+    my $file = shift || $self->get_ddl_file($schema);
+    open(  my $fh, "<",$file ) or die "couldnt open $file, $!";
     my $sql;
-    { local $/ = undef; $sql = <IN>; }
-    close IN;
-    ($schema->storage->dbh->do($_) || print "Error on SQL: $_\n") for split(/;\n/, $sql);
+    { local $/ = undef; $sql = <$fh>; }
+
+    foreach my $line (split(/;\n/, $sql)) {
+      print "$line\n";
+      next if(!$line);
+      next if($line =~ /^--/);
+      next if($line =~ /^BEGIN TRANSACTION/m);
+      next if($line =~ /^COMMIT/m);
+      next if $line =~ /^\s+$/; # skip whitespace only
+
+      $schema->storage->dbh->do($line) || print "Error on SQL: $line\n";
+    }
 }
  
 
@@ -138,6 +148,8 @@ sub populate_schema {
         [ 1, 'Caterwauler McCrae' ],
         [ 2, 'Random Boy Band' ],
         [ 3, 'We Are Goth' ],
+        [ 4, '' ], # Test overridden new will default name to "Test Name" using use_create => 1.
+        [ 32948, 'Big PK' ],
     ]);
 
     $schema->populate('CD', [
@@ -175,6 +187,9 @@ sub populate_schema {
         [ 1, 1 ],
         [ 1, 2 ],
         [ 1, 3 ],
+        [ 2, 1 ],
+        [ 2, 2 ],
+        [ 3, 3 ],
     ]);
 
     $schema->populate('Track', [