Commit | Line | Data |
cb551b07 |
1 | use DBIx::Class::Optional::Dependencies -skip_all_without => 'deploy'; |
6ebf5cbb |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | use Test::Exception; |
7c4ade2a |
8 | use Test::Warn; |
6ebf5cbb |
9 | use lib qw(t/lib); |
6c97a902 |
10 | use DBICTest; |
6ebf5cbb |
11 | use ViewDeps; |
51b31bbe |
12 | use ViewDepsBad; |
6ebf5cbb |
13 | |
b7b008a2 |
14 | #################### SANITY |
d40f513f |
15 | |
51b31bbe |
16 | my $view = DBIx::Class::ResultSource::View->new; |
66fb15b6 |
17 | |
9efcc79f |
18 | isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' ); |
19 | isa_ok( $view, 'DBIx::Class', 'A new view also' ); |
6ebf5cbb |
20 | |
e55d9d89 |
21 | can_ok( $view, $_ ) for qw/new from deploy_depends_on/; |
6ebf5cbb |
22 | |
b7b008a2 |
23 | #################### DEPS |
6c97a902 |
24 | { |
25 | my $schema |
26 | = ViewDeps->connect( DBICTest->_database (quote_char => '"') ); |
27 | ok( $schema, 'Connected to ViewDeps schema OK' ); |
9efcc79f |
28 | |
b7b008a2 |
29 | #################### DEPLOY |
bf5c3a3f |
30 | |
1f9712ad |
31 | $schema->deploy; |
2446dc59 |
32 | |
b7b008a2 |
33 | #################### DOES ORDERING WORK? |
34 | |
6c97a902 |
35 | my $sqlt_object = $schema->{sqlt}; |
36 | |
37 | is_deeply( |
38 | [ map { $_->name } $sqlt_object->get_views ], |
39 | [qw/ |
40 | a_name_artists |
41 | track_number_fives |
42 | year_2010_cds |
43 | ab_name_artists |
44 | year_2010_cds_with_many_tracks |
45 | aba_name_artists |
46 | aba_name_artists_and_2010_cds_with_many_tracks |
47 | /], |
8273e845 |
48 | "SQLT view order triumphantly matches our order." |
6c97a902 |
49 | ); |
bf5c3a3f |
50 | |
339f7f5d |
51 | #################### AND WHAT ABOUT USING THE SCHEMA? |
52 | |
6c97a902 |
53 | lives_ok( sub { $schema->resultset($_)->next }, "Query on $_ succeeds" ) |
8a8525be |
54 | for grep { |
55 | $schema->resultset($_) |
6c97a902 |
56 | ->result_source->isa('DBIx::Class::ResultSource::View') |
8a8525be |
57 | } @{ [ $schema->sources ] }; |
6c97a902 |
58 | } |
339f7f5d |
59 | |
51b31bbe |
60 | #################### AND WHAT ABOUT A BAD DEPS CHAIN IN A VIEW? |
61 | |
6c97a902 |
62 | { |
63 | my $schema2 |
64 | = ViewDepsBad->connect( DBICTest->_database ( quote_char => '"') ); |
65 | ok( $schema2, 'Connected to ViewDepsBad schema OK' ); |
51b31bbe |
66 | |
26c663f1 |
67 | my $lazy_view_validity = !( |
68 | $schema2->storage->_server_info->{normalized_dbms_version} |
69 | < |
70 | 3.009 |
71 | ); |
72 | |
51b31bbe |
73 | #################### DEPLOY2 |
74 | |
1f9712ad |
75 | warnings_exist { $schema2->deploy } |
26c663f1 |
76 | [ $lazy_view_validity ? () : qr/no such table: main.aba_name_artists/ ], |
d2f4cc4a |
77 | "Deploying the bad schema produces a warning: aba_name_artists was not created."; |
51b31bbe |
78 | |
79 | #################### DOES ORDERING WORK 2? |
80 | |
6c97a902 |
81 | my $sqlt_object2 = $schema2->{sqlt}; |
82 | |
83 | is_deeply( |
84 | [ map { $_->name } $sqlt_object2->get_views ], |
85 | [qw/ |
86 | a_name_artists |
87 | track_number_fives |
88 | year_2010_cds |
89 | ab_name_artists |
90 | year_2010_cds_with_many_tracks |
91 | aba_name_artists_and_2010_cds_with_many_tracks |
92 | aba_name_artists |
93 | /], |
8273e845 |
94 | "SQLT view order triumphantly matches our order." |
6c97a902 |
95 | ); |
51b31bbe |
96 | |
97 | #################### AND WHAT ABOUT USING THE SCHEMA2? |
98 | |
6c97a902 |
99 | lives_ok( sub { $schema2->resultset($_)->next }, "Query on $_ succeeds" ) |
51b31bbe |
100 | for grep { |
101 | $schema2->resultset($_) |
6c97a902 |
102 | ->result_source->isa('DBIx::Class::ResultSource::View') |
51b31bbe |
103 | } grep { !/AbaNameArtistsAnd2010CDsWithManyTracks/ } |
104 | @{ [ $schema2->sources ] }; |
105 | |
26c663f1 |
106 | $schema2->storage->dbh->do(q( DROP VIEW "aba_name_artists" )) |
107 | if $lazy_view_validity; |
108 | |
6c97a902 |
109 | throws_ok { $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next } |
26c663f1 |
110 | qr/no such table: (?:main\.)?aba_name_artists/, |
111 | sprintf( |
112 | "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the%s view does not exist", |
113 | $lazy_view_validity ? ' underlying' : '' |
114 | ) |
6c97a902 |
115 | ; |
c418c5cc |
116 | } |
c418c5cc |
117 | |
6ebf5cbb |
118 | done_testing; |