X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fdeploy_methods%2Fscript-helpers.t;fp=t%2Fdeploy_methods%2Fscript-helpers.t;h=c621f5305309bf4262ed640e7c9e90789d793816;hb=3467d1a5f6490810b79a74da040dd28396a9d7c4;hp=0000000000000000000000000000000000000000;hpb=dc262742363e497a67942488196484aae71f2d53;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git diff --git a/t/deploy_methods/script-helpers.t b/t/deploy_methods/script-helpers.t new file mode 100644 index 0000000..c621f53 --- /dev/null +++ b/t/deploy_methods/script-helpers.t @@ -0,0 +1,89 @@ +#!perl + +use strict; +use warnings; + +use Test::More; +use DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers ':all';; + +use lib 't/lib'; + +use DBICVersion_v1; +use DBICDHTest; + +my $dbh = DBICDHTest->dbh; +my @connection = (sub { $dbh }, { ignore_version => 1 }); +my $schema = DBICVersion::Schema->connect(@connection); +$schema->deploy; + +subtest dbh => sub { + my $ran; + dbh(sub { + my ($dbh, $versions) = @_; + + $ran = 1; + + is($dbh, $schema->storage->dbh, 'dbh is correctly reused'); + is_deeply $versions, [1,2], 'version correctly passed'; + isa_ok($dbh, 'DBI::db'); + })->($schema, [1,2]); + + ok $ran, 'coderef ran'; +}; + +subtest schema_from_schema_loader => sub { + use Test::Requires; + test_requires('DBIx::Class::Schema::Loader'); + my $build_sl_test = sub { + my @connection = @_; + + return sub { + my $ran; + my $outer_schema = DBICVersion::Schema->connect(@connection); + $outer_schema->deploy; + schema_from_schema_loader({ naming => 'v4' }, sub { + my ($schema, $versions) = @_; + + $ran = 1; + + is( + $outer_schema->storage->dbh, + $schema->storage->dbh, + 'dbh is correctly reused', + ); + is_deeply $versions, [2,3], 'version correctly passed'; + like(ref $schema, qr/SHSchema::\d+/, 'schema has expected type'); + isa_ok($schema, 'DBIx::Class::Schema', 'and schema is not totally worthless -'); + })->($outer_schema, [2,3]); + + ok $ran, 'coderef ran'; + } + }; + + subtest 'sub { $dbh }, ...' => $build_sl_test->( + sub { DBICDHTest->dbh }, + { ignore_version => 1 }, + ); + subtest '$dsn, $user, $pass, ...' => $build_sl_test->( + 'dbi:SQLite::memory:', undef, undef, + { RaiseError => 1 }, + { ignore_version => 1 } + ); + + subtest '({ dsn => ..., ... })' => $build_sl_test->({ + dsn => 'dbi:SQLite::memory:', + user => undef, + password => undef, + RaiseError => 1, + ignore_version => 1, + }); + + subtest '({ dbh_maker => ..., ... })' => $build_sl_test->({ + dbh_maker => sub { DBICDHTest->dbh }, + RaiseError => 1, + ignore_version => 1, + }); +}; + +done_testing; +