16 plan skip_all => 'Test needs ' .
17 DBIx::Class::Optional::Dependencies->req_missing_for('deploy')
18 unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy');
21 use_ok('DBIx::Class::ResultSource::View');
23 #################### SANITY
25 my $view = DBIx::Class::ResultSource::View->new;
27 isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' );
28 isa_ok( $view, 'DBIx::Class', 'A new view also' );
30 can_ok( $view, $_ ) for qw/new from deploy_depends_on/;
32 #################### DEPS
35 = ViewDeps->connect( DBICTest->_database (quote_char => '"') );
36 ok( $schema, 'Connected to ViewDeps schema OK' );
38 #################### DEPLOY
40 $schema->deploy( { add_drop_table => 1 } );
42 #################### DOES ORDERING WORK?
44 my $sqlt_object = $schema->{sqlt};
47 [ map { $_->name } $sqlt_object->get_views ],
53 year_2010_cds_with_many_tracks
55 aba_name_artists_and_2010_cds_with_many_tracks
57 "SQLT view order triumphantly matches our order."
60 #################### AND WHAT ABOUT USING THE SCHEMA?
62 lives_ok( sub { $schema->resultset($_)->next }, "Query on $_ succeeds" )
64 $schema->resultset($_)
65 ->result_source->isa('DBIx::Class::ResultSource::View')
66 } @{ [ $schema->sources ] };
69 #################### AND WHAT ABOUT A BAD DEPS CHAIN IN A VIEW?
73 = ViewDepsBad->connect( DBICTest->_database ( quote_char => '"') );
74 ok( $schema2, 'Connected to ViewDepsBad schema OK' );
76 #################### DEPLOY2
78 warnings_exist { $schema2->deploy( { add_drop_table => 1 } ) }
79 [qr/no such table: main.aba_name_artists/],
80 "Deploying the bad schema produces a warning: aba_name_artists was not created.";
82 #################### DOES ORDERING WORK 2?
84 my $sqlt_object2 = $schema2->{sqlt};
87 [ map { $_->name } $sqlt_object2->get_views ],
93 year_2010_cds_with_many_tracks
94 aba_name_artists_and_2010_cds_with_many_tracks
97 "SQLT view order triumphantly matches our order."
100 #################### AND WHAT ABOUT USING THE SCHEMA2?
102 lives_ok( sub { $schema2->resultset($_)->next }, "Query on $_ succeeds" )
104 $schema2->resultset($_)
105 ->result_source->isa('DBIx::Class::ResultSource::View')
106 } grep { !/AbaNameArtistsAnd2010CDsWithManyTracks/ }
107 @{ [ $schema2->sources ] };
109 throws_ok { $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next }
110 qr/no such table: aba_name_artists_and_2010_cds_with_many_tracks/,
111 "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the table does not exist"