Commit | Line | Data |
3467d1a5 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | use DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers ':all';; |
8 | |
9 | use lib 't/lib'; |
10 | |
11 | use DBICVersion_v1; |
12 | use DBICDHTest; |
13 | |
14 | my $dbh = DBICDHTest->dbh; |
15 | my @connection = (sub { $dbh }, { ignore_version => 1 }); |
16 | my $schema = DBICVersion::Schema->connect(@connection); |
17 | $schema->deploy; |
18 | |
19 | subtest dbh => sub { |
20 | my $ran; |
21 | dbh(sub { |
22 | my ($dbh, $versions) = @_; |
23 | |
24 | $ran = 1; |
25 | |
26 | is($dbh, $schema->storage->dbh, 'dbh is correctly reused'); |
27 | is_deeply $versions, [1,2], 'version correctly passed'; |
28 | isa_ok($dbh, 'DBI::db'); |
29 | })->($schema, [1,2]); |
30 | |
31 | ok $ran, 'coderef ran'; |
32 | }; |
33 | |
34 | subtest schema_from_schema_loader => sub { |
35 | use Test::Requires; |
36 | test_requires('DBIx::Class::Schema::Loader'); |
37 | my $build_sl_test = sub { |
38 | my @connection = @_; |
39 | |
40 | return sub { |
41 | my $ran; |
42 | my $outer_schema = DBICVersion::Schema->connect(@connection); |
43 | $outer_schema->deploy; |
44 | schema_from_schema_loader({ naming => 'v4' }, sub { |
45 | my ($schema, $versions) = @_; |
46 | |
47 | $ran = 1; |
48 | |
49 | is( |
50 | $outer_schema->storage->dbh, |
51 | $schema->storage->dbh, |
52 | 'dbh is correctly reused', |
53 | ); |
54 | is_deeply $versions, [2,3], 'version correctly passed'; |
55 | like(ref $schema, qr/SHSchema::\d+/, 'schema has expected type'); |
56 | isa_ok($schema, 'DBIx::Class::Schema', 'and schema is not totally worthless -'); |
57 | })->($outer_schema, [2,3]); |
58 | |
59 | ok $ran, 'coderef ran'; |
60 | } |
61 | }; |
62 | |
63 | subtest 'sub { $dbh }, ...' => $build_sl_test->( |
64 | sub { DBICDHTest->dbh }, |
65 | { ignore_version => 1 }, |
66 | ); |
67 | subtest '$dsn, $user, $pass, ...' => $build_sl_test->( |
68 | 'dbi:SQLite::memory:', undef, undef, |
69 | { RaiseError => 1 }, |
70 | { ignore_version => 1 } |
71 | ); |
72 | |
73 | subtest '({ dsn => ..., ... })' => $build_sl_test->({ |
74 | dsn => 'dbi:SQLite::memory:', |
75 | user => undef, |
76 | password => undef, |
77 | RaiseError => 1, |
78 | ignore_version => 1, |
79 | }); |
80 | |
81 | subtest '({ dbh_maker => ..., ... })' => $build_sl_test->({ |
82 | dbh_maker => sub { DBICDHTest->dbh }, |
83 | RaiseError => 1, |
84 | ignore_version => 1, |
85 | }); |
86 | }; |
87 | |
88 | done_testing; |
89 | |