From: Arthur Axel 'fREW' Schmidt Date: Mon, 31 May 2010 20:47:36 +0000 (-0500) Subject: Initial test for ignore_ddl X-Git-Tag: v0.001000_13~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cc7c22d91ae04a0c35f4a713521e58074149ccc3;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git Initial test for ignore_ddl --- diff --git a/t/02-instantiation-no-ddl.t b/t/02-instantiation-no-ddl.t new file mode 100644 index 0000000..ff169c3 --- /dev/null +++ b/t/02-instantiation-no-ddl.t @@ -0,0 +1,163 @@ +#!perl + +use strict; +use warnings; + +use lib 't/lib'; +use DBICDHTest; +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'; + +VERSION1: { + 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({ + ignore_ddl => 1, + 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_deploy; + + 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); + $DBICVersion::Schema::VERSION = 2; + ok($s, 'DBICVersion::Schema 2 instantiates correctly'); + my $handler = DH->new({ + ignore_ddl => 1, + script_directory => $sql_dir, + schema => $s, + databases => 'SQLite', + }); + + ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly'); + + my $version = $s->schema_version(); + $handler->prepare_deploy(); + 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); + $DBICVersion::Schema::VERSION = 3; + ok($s, 'DBICVersion::Schema 3 instantiates correctly'); + my $handler = DH->new({ + ignore_ddl => 1, + script_directory => $sql_dir, + schema => $s, + databases => 'SQLite', + }); + + ok($handler, 'DBIx::Class::DeploymentHandler w/3 instantiates correctly'); + + my $version = $s->schema_version(); + $handler->prepare_deploy; + 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'; +} + +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({ + ignore_ddl => 1, + script_directory => $sql_dir, + schema => $s, + databases => 'SQLite', + }); + + ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly'); + + my $version = $s->schema_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;