1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'deploy';
14 #################### SANITY
16 my $view = DBIx::Class::ResultSource::View->new;
18 isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' );
19 isa_ok( $view, 'DBIx::Class', 'A new view also' );
21 can_ok( $view, $_ ) for qw/new from deploy_depends_on/;
23 #################### DEPS
26 = ViewDeps->connect( DBICTest->_database (quote_char => '"') );
27 ok( $schema, 'Connected to ViewDeps schema OK' );
29 #################### DEPLOY
33 #################### DOES ORDERING WORK?
35 my $sqlt_object = $schema->{sqlt};
38 [ map { $_->name } $sqlt_object->get_views ],
44 year_2010_cds_with_many_tracks
46 aba_name_artists_and_2010_cds_with_many_tracks
48 "SQLT view order triumphantly matches our order."
51 #################### AND WHAT ABOUT USING THE SCHEMA?
53 lives_ok( sub { $schema->resultset($_)->next }, "Query on $_ succeeds" )
55 $schema->resultset($_)
56 ->result_source->isa('DBIx::Class::ResultSource::View')
57 } @{ [ $schema->sources ] };
60 #################### AND WHAT ABOUT A BAD DEPS CHAIN IN A VIEW?
64 = ViewDepsBad->connect( DBICTest->_database ( quote_char => '"') );
65 ok( $schema2, 'Connected to ViewDepsBad schema OK' );
67 my $lazy_view_validity = !(
68 $schema2->storage->_server_info->{normalized_dbms_version}
73 #################### DEPLOY2
75 warnings_exist { $schema2->deploy }
76 [ $lazy_view_validity ? () : qr/no such table: main.aba_name_artists/ ],
77 "Deploying the bad schema produces a warning: aba_name_artists was not created.";
79 #################### DOES ORDERING WORK 2?
81 my $sqlt_object2 = $schema2->{sqlt};
84 [ map { $_->name } $sqlt_object2->get_views ],
90 year_2010_cds_with_many_tracks
91 aba_name_artists_and_2010_cds_with_many_tracks
94 "SQLT view order triumphantly matches our order."
97 #################### AND WHAT ABOUT USING THE SCHEMA2?
99 lives_ok( sub { $schema2->resultset($_)->next }, "Query on $_ succeeds" )
101 $schema2->resultset($_)
102 ->result_source->isa('DBIx::Class::ResultSource::View')
103 } grep { !/AbaNameArtistsAnd2010CDsWithManyTracks/ }
104 @{ [ $schema2->sources ] };
106 $schema2->storage->dbh->do(q( DROP VIEW "aba_name_artists" ))
107 if $lazy_view_validity;
109 throws_ok { $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next }
110 qr/no such table: (?:main\.)?aba_name_artists/,
112 "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the%s view does not exist",
113 $lazy_view_validity ? ' underlying' : ''