good enough coverage for govt work (98.7)
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / 02-instantiation.t
index 3af52c0..4f8ca04 100644 (file)
 #!perl
 
 use Test::More;
+use Test::Exception;
+use File::Path 'remove_tree';
 
 use lib 't/lib';
-use DBICTest;
+use DBICDHTest;
 use DBIx::Class::DeploymentHandler;
-
+my $db = 'dbi:SQLite:db.db';
+my @connection = ($db, '', '', { ignore_version => 1 });
 my $sql_dir = 't/sql';
 
+DBICDHTest::ready;
+
 VERSION1: {
-       use_ok 'DBICVersion_v1';
-       my $s = DBICVersion::Schema->connect('dbi:SQLite::memory:');
-       ok($s, 'DBICVersion::Schema 1.0 instantiates correctly');
-       my $handler = DBIx::Class::DeploymentHandler->new({
-               schema => $s,
-       });
-
-       ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly');
-
-       my $version = $s->schema_version();
-       $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0);
-       ok(-e 't/sql/DBICVersion-Schema-1.0-SQLite.sql', 'DDL for 1.0 got created successfully');
+   use_ok 'DBICVersion_v1';
+   my $s = DBICVersion::Schema->connect(@connection);
+   ok($s, 'DBICVersion::Schema 1.0 instantiates correctly');
+   my $handler = DBIx::Class::DeploymentHandler->new({
+      upgrade_directory => $sql_dir,
+      schema => $s,
+      databases => 'SQLite',
+      sqltargs => { add_drop_table => 0 },
+   });
+
+   ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly');
+
+   my $version = $s->schema_version();
+   $handler->prepare_install();
+
+   dies_ok {
+      $s->resultset('Foo')->create({
+         bar => 'frew',
+      })
+   } 'schema not deployed';
+   $handler->install;
+   dies_ok {
+     $handler->install;
+   } 'cannot install twice';
+   lives_ok {
+      $s->resultset('Foo')->create({
+         bar => 'frew',
+      })
+   } 'schema is deployed';
 }
 
 VERSION2: {
-       use_ok 'DBICVersion_v2';
-       my $s = DBICVersion::Schema->connect('dbi:SQLite::memory:');
-       ok($s, 'DBICVersion::Schema 2.0 instantiates correctly');
-       my $handler = DBIx::Class::DeploymentHandler->new({
-               schema => $s,
-       });
-
-       ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly');
-
-       $version = $s->schema_version();
-       $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0);
-       $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '1.0');
-       ok(-e 't/sql/DBICVersion-Schema-2.0-SQLite.sql', 'DDL for 2.0 got created successfully');
-       ok(-e 't/sql/DBICVersion-Schema-1.0-2.0-SQLite.sql', 'DDL for migration from 1.0 to 2.0 got created successfully');
+   use_ok 'DBICVersion_v2';
+   my $s = DBICVersion::Schema->connect(@connection);
+   ok($s, 'DBICVersion::Schema 2.0 instantiates correctly');
+   my $handler = DBIx::Class::DeploymentHandler->new({
+      upgrade_directory => $sql_dir,
+      schema => $s,
+      databases => 'SQLite',
+   });
+
+   ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly');
+
+   $version = $s->schema_version();
+   $handler->prepare_install();
+   $handler->prepare_upgrade('1.0', $version);
+   $handler->prepare_upgrade($version, '1.0');
+   dies_ok {
+      $s->resultset('Foo')->create({
+         bar => 'frew',
+         baz => 'frew',
+      })
+   } 'schema not deployed';
+   dies_ok {
+      $s->resultset('Foo')->create({
+         bar => 'frew',
+         baz => 'frew',
+      })
+   } 'schema not uppgrayyed';
+   $handler->upgrade;
+   lives_ok {
+      $s->resultset('Foo')->create({
+         bar => 'frew',
+         baz => 'frew',
+      })
+   } 'schema is deployed';
 }
 
 VERSION3: {
-       use_ok 'DBICVersion_v3';
-       my $s = DBICVersion::Schema->connect('dbi:SQLite::memory:');
-       ok($s, 'DBICVersion::Schema 3.0 instantiates correctly');
-       my $handler = DBIx::Class::DeploymentHandler->new({
-               schema => $s,
-       });
-
-       ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly');
-
-       $version = $s->schema_version();
-       $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0);
-       $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '1.0');
-       $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '2.0');
-       ok(-e 't/sql/DBICVersion-Schema-3.0-SQLite.sql', 'DDL for 3.0 got created successfully');
-       ok(-e 't/sql/DBICVersion-Schema-1.0-3.0-SQLite.sql', 'DDL for migration from 1.0 to 3.0 got created successfully');
-       ok(-e 't/sql/DBICVersion-Schema-2.0-3.0-SQLite.sql', 'DDL for migration from 2.0 to 3.0 got created successfully');
+   use_ok 'DBICVersion_v3';
+   my $s = DBICVersion::Schema->connect(@connection);
+   ok($s, 'DBICVersion::Schema 3.0 instantiates correctly');
+   my $handler = DBIx::Class::DeploymentHandler->new({
+      upgrade_directory => $sql_dir,
+      schema => $s,
+      databases => 'SQLite',
+   });
+
+   ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly');
+
+   $version = $s->schema_version();
+   $handler->prepare_install;
+   $handler->prepare_upgrade( '1.0', $version );
+   $handler->prepare_upgrade( '2.0', $version );
+   dies_ok {
+      $s->resultset('Foo')->create({
+            bar => 'frew',
+            baz => 'frew',
+            biff => 'frew',
+         })
+   } 'schema not deployed';
+   $handler->upgrade;
+   lives_ok {
+      $s->resultset('Foo')->create({
+         bar => 'frew',
+         baz => 'frew',
+         biff => 'frew',
+      })
+   } 'schema is deployed';
 }
 
 done_testing;
+__END__
+
+vim: ts=2 sw=2 expandtab