X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F105view_deps.t;h=66e409db5cddbcd6cf55d1713efa5c725d0ad04c;hb=51b31bbe7d3359237fd2eb5e1f4aadb133578f25;hp=7905bd568005aa89acd7e62e3765b01482731c7d;hpb=339f7f5d918753b488b7cca97cb9b8b72e2e5f16;p=dbsrgits%2FDBIx-Class.git diff --git a/t/105view_deps.t b/t/105view_deps.t index 7905bd5..66e409d 100644 --- a/t/105view_deps.t +++ b/t/105view_deps.t @@ -7,6 +7,7 @@ use Test::More; use Test::Exception; use lib qw(t/lib); use ViewDeps; +use ViewDepsBad; BEGIN { use_ok('DBIx::Class::ResultSource::View'); @@ -14,7 +15,7 @@ BEGIN { #################### SANITY -my $view = DBIx::Class::ResultSource::View->new( { name => 'Quux' } ); +my $view = DBIx::Class::ResultSource::View->new; isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' ); isa_ok( $view, 'DBIx::Class', 'A new view also' ); @@ -23,76 +24,80 @@ can_ok( $view, $_ ) for qw/new from deploy_depends_on/; #################### DEPS -my @sql_files = glob("t/sql/ViewDeps*.sql"); -for (@sql_files) { - ok( unlink($_), "Deleted old SQL $_ OK" ); -} - -my $schema = ViewDeps->connect( 'dbi:SQLite::memory:', - { quote_char => '"', } ); +my $schema + = ViewDeps->connect( 'dbi:SQLite::memory:', { quote_char => '"', } ); ok( $schema, 'Connected to ViewDeps schema OK' ); -my $deps_ref = { - map { - $schema->resultset($_)->result_source->name => - $schema->resultset($_)->result_source->deploy_depends_on - } - grep { - $schema->resultset($_) - ->result_source->isa('DBIx::Class::ResultSource::View') - } @{ [ $schema->sources ] } -}; - -my @sorted_sources = - sort { - keys %{ $deps_ref->{$a} || {} } - <=> - keys %{ $deps_ref->{$b} || {} } - || $a cmp $b - } - keys %$deps_ref; - #################### DEPLOY -my $ddl_dir = "t/sql"; -$schema->create_ddl_dir( [ 'PostgreSQL', 'MySQL', 'SQLite' ], 0.1, $ddl_dir ); - -ok( -e $_, "$_ was created successfully" ) for @sql_files; - $schema->deploy( { add_drop_table => 1 } ); #################### DOES ORDERING WORK? -my $tr = $schema->{sqlt}; +my $sqlt_object = $schema->{sqlt}; -my @keys = keys %{$tr->{views}}; +my @keys = keys %{ $sqlt_object->{views} }; -my @sqlt_sources = - sort { - $tr->{views}->{$a}->{order} - cmp - $tr->{views}->{$b}->{order} - } - @keys; +my @sqlt_sources = sort { + $sqlt_object->{views}->{$a}->{order} + cmp $sqlt_object->{views}->{$b}->{order} +} @keys; -is_deeply(\@sorted_sources,\@sqlt_sources,"SQLT view order triumphantly matches our order."); +my @expected + = 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/; + +is_deeply( \@expected, \@sqlt_sources, + "SQLT view order triumphantly matches our order." ); #################### AND WHAT ABOUT USING THE SCHEMA? -my $a_name_rs = $schema->resultset('ANameArtists'); -my $ab_name_rs = $schema->resultset('AbNameArtists'); -my $aba_name_rs = $schema->resultset('AbaNameArtists'); -my $aba_name_cds_rs = $schema->resultset('AbaNameArtistsAnd2010CDsWithManyTracks'); -my $track_five_rs = $schema->resultset('TrackNumberFives'); -my $year_2010_rs = $schema->resultset('Year2010CDs'); -my $year_2010_cds_rs = $schema->resultset('Year2010CDsWithManyTracks'); - -ok($a_name_rs, "ANameArtists resultset is OK"); -ok($ab_name_rs, "AbNameArtists resultset is OK"); -ok($aba_name_rs, "AbaNameArtists resultset is OK"); -ok($aba_name_cds_rs, "AbaNameArtistsAnd2010CDsWithManyTracks resultset is OK"); -ok($track_five_rs, "TrackNumberFives resultset is OK"); -ok($year_2010_rs, "Year2010CDs resultset is OK"); -ok($year_2010_cds_rs, "Year2010CDsWithManyTracks resultset is OK"); +lives_ok( sub { $schema->resultset($_)->next }, "Query on $_ succeeds" ) + for grep { + $schema->resultset($_) + ->result_source->isa('DBIx::Class::ResultSource::View') + } @{ [ $schema->sources ] }; + +#################### AND WHAT ABOUT A BAD DEPS CHAIN IN A VIEW? + +my $schema2 + = ViewDepsBad->connect( 'dbi:SQLite::memory:', { quote_char => '"', } ); +ok( $schema2, 'Connected to ViewDepsBad schema OK' ); + +#################### DEPLOY2 + +$schema2->deploy( { add_drop_table => 1 } ); + +#################### DOES ORDERING WORK 2? + +my $sqlt_object2 = $schema2->{sqlt}; + +my @keys2 = keys %{ $sqlt_object->{views} }; + +my @sqlt_sources2 = sort { + $sqlt_object->{views}->{$a}->{order} + cmp $sqlt_object->{views}->{$b}->{order} +} @keys2; + +my @expected2 + = 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/; + +is_deeply( \@expected2, \@sqlt_sources2, + "SQLT view order triumphantly matches our order." ); + +#################### AND WHAT ABOUT USING THE SCHEMA2? + +lives_ok( sub { $schema2->resultset($_)->next }, "Query on $_ succeeds" ) + for grep { + $schema2->resultset($_) + ->result_source->isa('DBIx::Class::ResultSource::View') + } grep { !/AbaNameArtistsAnd2010CDsWithManyTracks/ } + @{ [ $schema2->sources ] }; + +dies_ok( + sub { + $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next; + }, + "Query on AbaNameArtistsAnd2010CDsWithManyTracks fails, because of incorrect deploy_depends_on in AbaNameArtists" +); done_testing;