Commit | Line | Data |
6ebf5cbb |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | use Test::Exception; |
8 | use lib qw(t/lib); |
6ebf5cbb |
9 | use ViewDeps; |
e55d9d89 |
10 | use Devel::Dwarn; |
6ebf5cbb |
11 | |
12 | BEGIN { |
13 | use_ok('DBIx::Class::ResultSource::View'); |
14 | } |
15 | |
d40f513f |
16 | ### SANITY |
17 | |
1e70d9dc |
18 | my $view = DBIx::Class::ResultSource::View->new( { name => 'Quux' } ); |
66fb15b6 |
19 | |
9efcc79f |
20 | isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' ); |
21 | isa_ok( $view, 'DBIx::Class', 'A new view also' ); |
6ebf5cbb |
22 | |
e55d9d89 |
23 | can_ok( $view, $_ ) for qw/new from deploy_depends_on/; |
6ebf5cbb |
24 | |
d40f513f |
25 | ### DEPS |
6ebf5cbb |
26 | |
27 | my $schema = ViewDeps->connect; |
1e70d9dc |
28 | ok( $schema, 'Connected to ViewDeps schema OK' ); |
e55d9d89 |
29 | my $bar_rs = $schema->resultset('Bar'); |
9efcc79f |
30 | |
e55d9d89 |
31 | #diag(DwarnS $bar_rs->result_source); |
6ebf5cbb |
32 | |
9efcc79f |
33 | my @bar_deps |
34 | = keys %{ $schema->resultset('Bar')->result_source->deploy_depends_on }; |
6ebf5cbb |
35 | |
9efcc79f |
36 | my @foo_deps |
37 | = keys %{ $schema->resultset('Foo')->result_source->deploy_depends_on }; |
66fb15b6 |
38 | |
1e70d9dc |
39 | isa_ok( $schema->resultset('Bar')->result_source, |
40 | 'DBIx::Class::ResultSource::View', 'Bar' ); |
66fb15b6 |
41 | |
9efcc79f |
42 | is( $bar_deps[0], 'baz', 'which is reported to depend on baz...' ); |
bf5c3a3f |
43 | is( $bar_deps[1], 'mixin', 'and on mixin.' ); |
1e70d9dc |
44 | is( $foo_deps[0], undef, 'Foo has no dependencies...' ); |
45 | |
46 | isa_ok( |
47 | $schema->resultset('Foo')->result_source, |
48 | 'DBIx::Class::ResultSource::View', |
49 | 'though Foo' |
50 | ); |
d40f513f |
51 | isa_ok( |
52 | $schema->resultset('Baz')->result_source, |
53 | 'DBIx::Class::ResultSource::Table', |
54 | "Baz on the other hand" |
55 | ); |
56 | dies_ok { |
9efcc79f |
57 | ViewDeps::Result::Baz->result_source_instance |
58 | ->deploy_depends_on("ViewDeps::Result::Mixin"); |
d40f513f |
59 | } |
e55d9d89 |
60 | "...and you cannot use deploy_depends_on with that"; |
6ebf5cbb |
61 | |
9efcc79f |
62 | diag( |
63 | "ViewDeps::Foo view definition: ", |
64 | ViewDeps->source('Foo')->view_definition |
65 | ); |
66 | diag( "schema->rs(Bar) view definition: ", |
67 | $schema->resultset('Bar')->result_source->view_definition ); |
bf5c3a3f |
68 | |
9efcc79f |
69 | my $dir = "t/sql"; # tempdir(CLEANUP => 0); |
70 | $schema->create_ddl_dir( ['PostgreSQL','SQLite'], 0.1, $dir ); |
bf5c3a3f |
71 | |
6ebf5cbb |
72 | done_testing; |