15 plan skip_all => 'Test needs ' .
16 DBIx::Class::Optional::Dependencies->req_missing_for('deploy')
17 unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy');
20 use_ok('DBIx::Class::ResultSource::View');
22 #################### SANITY
24 my $view = DBIx::Class::ResultSource::View->new;
26 isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' );
27 isa_ok( $view, 'DBIx::Class', 'A new view also' );
29 can_ok( $view, $_ ) for qw/new from deploy_depends_on/;
31 #################### DEPS
34 = ViewDeps->connect( 'dbi:SQLite::memory:', { quote_char => '"', } );
35 ok( $schema, 'Connected to ViewDeps schema OK' );
37 #################### DEPLOY
39 $schema->deploy( { add_drop_table => 1 } );
41 #################### DOES ORDERING WORK?
43 my $sqlt_object = $schema->{sqlt};
45 my @keys = keys %{ $sqlt_object->{views} };
47 my @sqlt_sources = sort {
48 $sqlt_object->{views}->{$a}->{order}
49 cmp $sqlt_object->{views}->{$b}->{order}
53 = qw/a_name_artists track_number_fives year_2010_cds ab_name_artists year_2010_cds_with_many_tracks aba_name_artists aba_name_artists_and_2010_cds_with_many_tracks/;
55 is_deeply( \@expected, \@sqlt_sources,
56 "SQLT view order triumphantly matches our order." );
58 #################### AND WHAT ABOUT USING THE SCHEMA?
60 lives_ok( sub { $schema->resultset($_)->next }, "Query on $_ succeeds" )
62 $schema->resultset($_)
63 ->result_source->isa('DBIx::Class::ResultSource::View')
64 } @{ [ $schema->sources ] };
66 #################### AND WHAT ABOUT A BAD DEPS CHAIN IN A VIEW?
69 = ViewDepsBad->connect( 'dbi:SQLite::memory:', { quote_char => '"', } );
70 ok( $schema2, 'Connected to ViewDepsBad schema OK' );
72 #################### DEPLOY2
74 warnings_exist { $schema2->deploy( { add_drop_table => 1 } ); }
75 [qr/no such table: main.aba_name_artists/],
76 "Deploying the bad schema produces a warning: aba_name_artists was not created.";
78 #################### DOES ORDERING WORK 2?
80 my $sqlt_object2 = $schema2->{sqlt};
82 my @keys2 = keys %{ $sqlt_object->{views} };
84 my @sqlt_sources2 = sort {
85 $sqlt_object->{views}->{$a}->{order}
86 cmp $sqlt_object->{views}->{$b}->{order}
90 = qw/a_name_artists track_number_fives year_2010_cds ab_name_artists year_2010_cds_with_many_tracks aba_name_artists aba_name_artists_and_2010_cds_with_many_tracks/;
92 is_deeply( \@expected2, \@sqlt_sources2,
93 "SQLT view order triumphantly matches our order." );
95 #################### AND WHAT ABOUT USING THE SCHEMA2?
97 lives_ok( sub { $schema2->resultset($_)->next }, "Query on $_ succeeds" )
99 $schema2->resultset($_)
100 ->result_source->isa('DBIx::Class::ResultSource::View')
101 } grep { !/AbaNameArtistsAnd2010CDsWithManyTracks/ }
102 @{ [ $schema2->sources ] };
106 $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next;
108 "Query on AbaNameArtistsAnd2010CDsWithManyTracks dies, because of incorrect deploy_depends_on in AbaNameArtists"
112 $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next;
114 qr/no such table: aba_name_artists_and_2010_cds_with_many_tracks/,
115 "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the table does not exist";