Correctly set the version deployed to the version requested on install
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / 02-instantiation-wo-component.t
index e607828..0eabb14 100644 (file)
@@ -14,8 +14,8 @@ use Test::Exception;
 
 DBICDHTest::ready;
 
-my $db = 'dbi:SQLite:db.db';
-my @connection = ($db, '', '', { ignore_version => 1 });
+my $dbh = DBICDHTest::dbh();
+my @connection = (sub { $dbh }, { ignore_version => 1 });
 my $sql_dir = 't/sql';
 
 VERSION1: {
@@ -33,14 +33,14 @@ VERSION1: {
   ok($handler, 'DBIx::Class::DeploymentHandler w/1 instantiates correctly');
 
   my $version = $s->schema_version;
-  $handler->prepare_deploy;
+  $handler->prepare_install;
 
   dies_ok {
     $s->resultset('Foo')->create({
       bar => 'frew',
     })
   } 'schema not deployed';
-  $handler->install;
+  $handler->install({ version => 1 });
   dies_ok {
     $handler->install;
   } 'cannot install twice';
@@ -55,6 +55,20 @@ VERSION2: {
   use_ok 'DBICVersion_v2';
   my $s = DBICVersion::Schema->connect(@connection);
   $DBICVersion::Schema::VERSION = 2;
+  subtest 'bug deploying first version' => sub {
+    my $dbh = DBICDHTest::dbh();
+    my @connection = (sub { $dbh }, { ignore_version => 1 });
+    my $s = DBICVersion::Schema->connect(@connection);
+
+    my $handler = DH->new({
+      script_directory => $sql_dir,
+      schema => $s,
+      databases => 'SQLite',
+    });
+    $handler->install({ version => 1 });
+    is($handler->database_version, 1, 'correctly set version to 1');
+  };
+
   ok($s, 'DBICVersion::Schema 2 instantiates correctly');
   my $handler = DH->new({
     script_directory => $sql_dir,
@@ -65,7 +79,7 @@ VERSION2: {
   ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly');
 
   my $version = $s->schema_version();
-  $handler->prepare_deploy();
+  $handler->prepare_install;
   $handler->prepare_upgrade({ from_version => 1, to_version => $version });
   dies_ok {
     $s->resultset('Foo')->create({
@@ -102,7 +116,7 @@ VERSION3: {
   ok($handler, 'DBIx::Class::DeploymentHandler w/3 instantiates correctly');
 
   my $version = $s->schema_version();
-  $handler->prepare_deploy;
+  $handler->prepare_install;
   $handler->prepare_upgrade({ from_version => 2, to_version => $version });
   dies_ok {
     $s->resultset('Foo')->create({