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');
18 use_ok('DBIx::Class::ResultSource::View');
21 #################### SANITY
23 my $view = DBIx::Class::ResultSource::View->new;
25 isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' );
26 isa_ok( $view, 'DBIx::Class', 'A new view also' );
28 can_ok( $view, $_ ) for qw/new from deploy_depends_on/;
30 #################### DEPS
33 = ViewDeps->connect( 'dbi:SQLite::memory:', { quote_char => '"', } );
34 ok( $schema, 'Connected to ViewDeps schema OK' );
36 #################### DEPLOY
38 $schema->deploy( { add_drop_table => 1 } );
40 #################### DOES ORDERING WORK?
42 my $sqlt_object = $schema->{sqlt};
44 my @keys = keys %{ $sqlt_object->{views} };
46 my @sqlt_sources = sort {
47 $sqlt_object->{views}->{$a}->{order}
48 cmp $sqlt_object->{views}->{$b}->{order}
52 = 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/;
54 is_deeply( \@expected, \@sqlt_sources,
55 "SQLT view order triumphantly matches our order." );
57 #################### AND WHAT ABOUT USING THE SCHEMA?
59 lives_ok( sub { $schema->resultset($_)->next }, "Query on $_ succeeds" )
61 $schema->resultset($_)
62 ->result_source->isa('DBIx::Class::ResultSource::View')
63 } @{ [ $schema->sources ] };
65 #################### AND WHAT ABOUT A BAD DEPS CHAIN IN A VIEW?
68 = ViewDepsBad->connect( 'dbi:SQLite::memory:', { quote_char => '"', } );
69 ok( $schema2, 'Connected to ViewDepsBad schema OK' );
71 #################### DEPLOY2
73 warnings_exist { $schema2->deploy( { add_drop_table => 1 } ); }
74 [qr/no such table: main.aba_name_artists/],
75 "Deploying the bad schema produces a warning: aba_name_artists was not created.";
77 #################### DOES ORDERING WORK 2?
79 my $sqlt_object2 = $schema2->{sqlt};
81 my @keys2 = keys %{ $sqlt_object->{views} };
83 my @sqlt_sources2 = sort {
84 $sqlt_object->{views}->{$a}->{order}
85 cmp $sqlt_object->{views}->{$b}->{order}
89 = 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/;
91 is_deeply( \@expected2, \@sqlt_sources2,
92 "SQLT view order triumphantly matches our order." );
94 #################### AND WHAT ABOUT USING THE SCHEMA2?
96 lives_ok( sub { $schema2->resultset($_)->next }, "Query on $_ succeeds" )
98 $schema2->resultset($_)
99 ->result_source->isa('DBIx::Class::ResultSource::View')
100 } grep { !/AbaNameArtistsAnd2010CDsWithManyTracks/ }
101 @{ [ $schema2->sources ] };
105 $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next;
107 "Query on AbaNameArtistsAnd2010CDsWithManyTracks dies, because of incorrect deploy_depends_on in AbaNameArtists"
111 $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next;
113 qr/no such table: aba_name_artists_and_2010_cds_with_many_tracks/,
114 "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the table does not exist";