From: Arthur Axel 'fREW' Schmidt Date: Sun, 21 Mar 2010 05:32:48 +0000 (-0500) Subject: good inital test for dm::sqlt X-Git-Tag: v0.001000_01~61 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b98a3a18e1c3df8bb26fafe6f45efa1bdefb064;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git good inital test for dm::sqlt --- diff --git a/t/02-instantiation.t b/t/02-instantiation.t index 156bb24..4f8ca04 100644 --- a/t/02-instantiation.t +++ b/t/02-instantiation.t @@ -28,7 +28,6 @@ VERSION1: { 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({ @@ -62,15 +61,12 @@ VERSION2: { $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', @@ -102,9 +98,6 @@ VERSION3: { $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', diff --git a/t/deploy_methods/sql_translator.t b/t/deploy_methods/sql_translator.t index 4729a41..857129e 100644 --- a/t/deploy_methods/sql_translator.t +++ b/t/deploy_methods/sql_translator.t @@ -6,6 +6,7 @@ use Test::Exception; use lib 't/lib'; use DBICDHTest; use aliased 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator'; +use File::Spec::Functions; my $db = 'dbi:SQLite:db.db'; my @connection = ($db, '', '', { ignore_version => 1 }); @@ -17,12 +18,127 @@ VERSION1: { use_ok 'DBICVersion_v1'; my $s = DBICVersion::Schema->connect(@connection); my $dm = Translator->new({ - schema => $s, + schema => $s, upgrade_directory => $sql_dir, - databases => ['SQLite'], + databases => ['SQLite'], + sqltargs => { add_drop_table => 0 }, }); ok( $dm, 'DBIC::DH::DM::SQL::Translator gets instantiated correctly' ); + + $dm->prepare_install; + + ok( + -f catfile(qw( t sql SQLite schema 1.0 001-auto.sql )), + '1.0 schema gets generated properly' + ); + + dies_ok { + $s->resultset('Foo')->create({ + bar => 'frew', + }) + } 'schema not deployed'; + + $dm->_deploy; + + lives_ok { + $s->resultset('Foo')->create({ + bar => 'frew', + }) + } 'schema is deployed'; +} + +VERSION2: { + use_ok 'DBICVersion_v2'; + my $s = DBICVersion::Schema->connect(@connection); + my $dm = Translator->new({ + schema => $s, + upgrade_directory => $sql_dir, + databases => ['SQLite'], + sqltargs => { add_drop_table => 0 }, + }); + + ok( $dm, 'DBIC::DH::SQL::Translator w/2.0 instantiates correctly'); + + $version = $s->schema_version(); + $dm->prepare_install(); + ok( + -f catfile(qw( t sql SQLite schema 2.0 001-auto.sql )), + '2.0 schema gets generated properly' + ); + $dm->prepare_upgrade('1.0', $version); + ok( + -f catfile(qw( t sql SQLite up 1.0-2.0 001-auto.sql )), + '1.0-2.0 diff gets generated properly' + ); + $dm->prepare_downgrade($version, '1.0'); + ok( + -f catfile(qw( t sql SQLite down 2.0-1.0 001-auto.sql )), + '1.0-2.0 diff gets generated properly' + ); + 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'; + $dm->_upgrade_single_step([qw( 1.0 2.0 )]); + lives_ok { + $s->resultset('Foo')->create({ + bar => 'frew', + baz => 'frew', + }) + } 'schema is deployed'; } +VERSION3: { + use_ok 'DBICVersion_v3'; + my $s = DBICVersion::Schema->connect(@connection); + my $dm = Translator->new({ + schema => $s, + upgrade_directory => $sql_dir, + databases => ['SQLite'], + sqltargs => { add_drop_table => 0 }, + }); + + ok( $dm, 'DBIC::DH::SQL::Translator w/3.0 instantiates correctly'); + + $version = $s->schema_version(); + $dm->prepare_install; + ok( + -f catfile(qw( t sql SQLite schema 3.0 001-auto.sql )), + '2.0 schema gets generated properly' + ); + $dm->prepare_upgrade( '1.0', $version ); + ok( + -f catfile(qw( t sql SQLite up 1.0-2.0 001-auto.sql )), + '1.0-3.0 diff gets generated properly' + ); + $dm->prepare_upgrade( '2.0', $version ); + ok( + -f catfile(qw( t sql SQLite up 1.0-2.0 001-auto.sql )), + '2.0-3.0 diff gets generated properly' + ); + dies_ok { + $s->resultset('Foo')->create({ + bar => 'frew', + baz => 'frew', + biff => 'frew', + }) + } 'schema not deployed'; + $dm->_upgrade_single_step([qw( 2.0 3.0 )]); + lives_ok { + $s->resultset('Foo')->create({ + bar => 'frew', + baz => 'frew', + biff => 'frew', + }) + } 'schema is deployed'; +} done_testing;