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