X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F02-instantiation-wo-component.t;h=abe28e416c6117e5f48a6493fe7dc750b649984d;hb=297e662fab9ba5a6798db95abbdbca2181373c92;hp=f3ea2ac0fe333251a75b1684b63bca57f57b4cc9;hpb=53de57ed75cc2baf105fd7013769b0c6572c6dbe;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git diff --git a/t/02-instantiation-wo-component.t b/t/02-instantiation-wo-component.t index f3ea2ac..abe28e4 100644 --- a/t/02-instantiation-wo-component.t +++ b/t/02-instantiation-wo-component.t @@ -8,15 +8,13 @@ use DBICDHTest; use DBIx::Class::DeploymentHandler; use aliased 'DBIx::Class::DeploymentHandler', 'DH'; -use File::Path 'remove_tree'; use Test::More; -use Test::Exception; +use File::Temp 'tempdir'; +use Test::Fatal qw(lives_ok dies_ok); -DBICDHTest::ready; - -my $db = 'dbi:SQLite:db.db'; -my @connection = ($db, '', '', { ignore_version => 1 }); -my $sql_dir = 't/sql'; +my $dbh = DBICDHTest::dbh(); +my @connection = (sub { $dbh }, { ignore_version => 1 }); +my $sql_dir = tempdir( CLEANUP => 1 ); VERSION1: { use_ok 'DBICVersion_v1'; @@ -24,7 +22,7 @@ VERSION1: { $DBICVersion::Schema::VERSION = 1; ok($s, 'DBICVersion::Schema 1 instantiates correctly'); my $handler = DH->new({ - upgrade_directory => $sql_dir, + script_directory => $sql_dir, schema => $s, databases => 'SQLite', sql_translator_args => { add_drop_table => 0 }, @@ -33,14 +31,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,9 +53,23 @@ 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({ - upgrade_directory => $sql_dir, + script_directory => $sql_dir, schema => $s, databases => 'SQLite', }); @@ -65,8 +77,8 @@ VERSION2: { ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly'); my $version = $s->schema_version(); - $handler->prepare_deploy(); - $handler->prepare_upgrade(1, $version); + $handler->prepare_install; + $handler->prepare_upgrade({ from_version => 1, to_version => $version }); dies_ok { $s->resultset('Foo')->create({ bar => 'frew', @@ -94,7 +106,7 @@ VERSION3: { $DBICVersion::Schema::VERSION = 3; ok($s, 'DBICVersion::Schema 3 instantiates correctly'); my $handler = DH->new({ - upgrade_directory => $sql_dir, + script_directory => $sql_dir, schema => $s, databases => 'SQLite', }); @@ -102,8 +114,8 @@ VERSION3: { ok($handler, 'DBIx::Class::DeploymentHandler w/3 instantiates correctly'); my $version = $s->schema_version(); - $handler->prepare_deploy; - $handler->prepare_upgrade( 2, $version ); + $handler->prepare_install; + $handler->prepare_upgrade({ from_version => 2, to_version => $version }); dies_ok { $s->resultset('Foo')->create({ bar => 'frew', @@ -127,7 +139,7 @@ DOWN2: { $DBICVersion::Schema::VERSION = 2; ok($s, 'DBICVersion::Schema 2 instantiates correctly'); my $handler = DH->new({ - upgrade_directory => $sql_dir, + script_directory => $sql_dir, schema => $s, databases => 'SQLite', }); @@ -135,7 +147,7 @@ DOWN2: { ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly'); my $version = $s->schema_version(); - $handler->prepare_downgrade(3, $version); + $handler->prepare_downgrade({ from_version => 3, to_version => $version }); lives_ok { $s->resultset('Foo')->create({ bar => 'frew',