X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-DeploymentHandler.git;a=blobdiff_plain;f=t%2F02-instantiation.t;h=33de7506c21efbb9e3867f5307d35a9ab4c84edf;hp=96996441603876c41db25bed078ad559cd4f3fd1;hb=5761fe02e68a534a47a6a5ff905c73ec991703cd;hpb=84afdcb37642d456f42de873944347b45555066b diff --git a/t/02-instantiation.t b/t/02-instantiation.t index 9699644..33de750 100644 --- a/t/02-instantiation.t +++ b/t/02-instantiation.t @@ -1,129 +1,162 @@ #!perl -use Test::More; -use Test::Exception; -use File::Path 'remove_tree'; +use strict; +use warnings; use lib 't/lib'; use DBICDHTest; -use DBICTest; use DBIx::Class::DeploymentHandler; +use aliased 'DBIx::Class::DeploymentHandler', 'DH'; + +use File::Path 'remove_tree'; +use Test::More; +use Test::Exception; + +DBICDHTest::ready; + 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(@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(); - #ok(-e 't/sql/DBICVersion-Schema-schema-1.0-SQLite.sql', 'DDL for 1.0 got created successfully'); - - 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'; + use_ok 'DBICVersion_v1'; + my $s = DBICVersion::Schema->connect(@connection); + $DBICVersion::Schema::VERSION = 1; + ok($s, 'DBICVersion::Schema 1 instantiates correctly'); + my $handler = DH->new({ + script_directory => $sql_dir, + schema => $s, + databases => 'SQLite', + sql_translator_args => { add_drop_table => 0 }, + }); + + ok($handler, 'DBIx::Class::DeploymentHandler w/1 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(@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'); - #ok(-e 't/sql/DBICVersion-Schema-schema-2.0-SQLite.sql', 'DDL for 2.0 got created successfully'); - #ok(-e 't/sql/DBICVersion-Schema-diff-1.0-2.0-SQLite.sql', 'DDL for migration from 1.0 to 2.0 got created successfully'); - dies_ok { - $s->resultset('Foo')->create({ - bar => 'frew', - baz => 'frew', - }) - } 'schema not deployed'; - #$handler->install('1.0'); - 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'; + use_ok 'DBICVersion_v2'; + my $s = DBICVersion::Schema->connect(@connection); + $DBICVersion::Schema::VERSION = 2; + ok($s, 'DBICVersion::Schema 2 instantiates correctly'); + my $handler = DH->new({ + script_directory => $sql_dir, + schema => $s, + databases => 'SQLite', + }); + + ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly'); + + my $version = $s->schema_version(); + $handler->prepare_install; + $handler->prepare_upgrade({ from_version => 1, to_version => $version} ); + 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(@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 ); - #ok(-e 't/sql/DBICVersion-Schema-schema-3.0-SQLite.sql', 'DDL for 3.0 got created successfully'); - #ok(-e 't/sql/DBICVersion-Schema-diff-1.0-3.0-SQLite.sql', 'DDL for migration from 1.0 to 3.0 got created successfully'); - #ok(-e 't/sql/DBICVersion-Schema-diff-2.0-3.0-SQLite.sql', 'DDL for migration from 2.0 to 3.0 got created successfully'); - 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', + use_ok 'DBICVersion_v3'; + my $s = DBICVersion::Schema->connect(@connection); + $DBICVersion::Schema::VERSION = 3; + ok($s, 'DBICVersion::Schema 3 instantiates correctly'); + my $handler = DH->new({ + script_directory => $sql_dir, + schema => $s, + databases => 'SQLite', + }); + + ok($handler, 'DBIx::Class::DeploymentHandler w/3 instantiates correctly'); + + my $version = $s->schema_version(); + $handler->prepare_install; + $handler->prepare_upgrade({ from_version => 2, to_version => $version }); + dies_ok { + $s->resultset('Foo')->create({ + bar => 'frew', + baz => 'frew', + biff => 'frew', }) - } 'schema is deployed'; + } 'schema not deployed'; + $handler->upgrade; + lives_ok { + $s->resultset('Foo')->create({ + bar => 'frew', + baz => 'frew', + biff => 'frew', + }) + } 'schema is deployed'; } -done_testing; -__END__ +DOWN2: { + use_ok 'DBICVersion_v4'; + my $s = DBICVersion::Schema->connect(@connection); + $DBICVersion::Schema::VERSION = 2; + ok($s, 'DBICVersion::Schema 2 instantiates correctly'); + my $handler = DH->new({ + script_directory => $sql_dir, + schema => $s, + databases => 'SQLite', + }); + + ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly'); -vim: ts=2 sw=2 expandtab + my $version = $s->schema_version(); + $handler->prepare_downgrade({ from_version => 3, to_version => $version }); + lives_ok { + $s->resultset('Foo')->create({ + bar => 'frew', + baz => 'frew', + biff => 'frew', + }) + } 'schema at version 3'; + $handler->downgrade; + dies_ok { + $s->resultset('Foo')->create({ + bar => 'frew', + baz => 'frew', + biff => 'frew', + }) + } 'schema not at version 3'; + lives_ok { + $s->resultset('Foo')->create({ + bar => 'frew', + baz => 'frew', + }) + } 'schema is at version 2'; +} + +done_testing;