1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'deploy';
15 #################### SANITY
17 my $view = DBIx::Class::ResultSource::View->new;
19 isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' );
20 isa_ok( $view, 'DBIx::Class', 'A new view also' );
22 can_ok( $view, $_ ) for qw/new from deploy_depends_on/;
24 #################### DEPS
27 = ViewDeps->connect( DBICTest->_database (quote_char => '"') );
28 ok( $schema, 'Connected to ViewDeps schema OK' );
30 #################### DEPLOY
34 #################### DOES ORDERING WORK?
36 my $sqlt_object = $schema->{sqlt};
39 [ map { $_->name } $sqlt_object->get_views ],
45 year_2010_cds_with_many_tracks
47 aba_name_artists_and_2010_cds_with_many_tracks
49 "SQLT view order triumphantly matches our order."
52 #################### AND WHAT ABOUT USING THE SCHEMA?
54 lives_ok( sub { $schema->resultset($_)->next }, "Query on $_ succeeds" )
56 $schema->resultset($_)
57 ->result_source->isa('DBIx::Class::ResultSource::View')
58 } @{ [ $schema->sources ] };
61 #################### AND WHAT ABOUT A BAD DEPS CHAIN IN A VIEW?
65 = ViewDepsBad->connect( DBICTest->_database ( quote_char => '"') );
66 ok( $schema2, 'Connected to ViewDepsBad schema OK' );
68 my $lazy_view_validity = !(
69 $schema2->storage->_server_info->{normalized_dbms_version}
74 #################### DEPLOY2
76 warnings_exist { $schema2->deploy }
77 [ $lazy_view_validity ? () : qr/no such table: main.aba_name_artists/ ],
78 "Deploying the bad schema produces a warning: aba_name_artists was not created.";
80 #################### DOES ORDERING WORK 2?
82 my $sqlt_object2 = $schema2->{sqlt};
85 [ map { $_->name } $sqlt_object2->get_views ],
91 year_2010_cds_with_many_tracks
92 aba_name_artists_and_2010_cds_with_many_tracks
95 "SQLT view order triumphantly matches our order."
98 #################### AND WHAT ABOUT USING THE SCHEMA2?
100 lives_ok( sub { $schema2->resultset($_)->next }, "Query on $_ succeeds" )
102 $schema2->resultset($_)
103 ->result_source->isa('DBIx::Class::ResultSource::View')
104 } grep { !/AbaNameArtistsAnd2010CDsWithManyTracks/ }
105 @{ [ $schema2->sources ] };
107 $schema2->storage->dbh->do(q( DROP VIEW "aba_name_artists" ))
108 if $lazy_view_validity;
110 throws_ok { $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next }
111 qr/no such table: (?:main\.)?aba_name_artists/,
113 "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the%s view does not exist",
114 $lazy_view_validity ? ' underlying' : ''