X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F105view_deps.t;h=21aa92bff451165ea4da1d0e57b8314b56e24370;hb=992a24f640638601acb795c24af493d789368400;hp=2b8ccf243c2ce4e3a3bcad316e9dda1189216e12;hpb=6ebf5cbb4dff9f173f41d5f31f2169f899dee492;p=dbsrgits%2FDBIx-Class.git diff --git a/t/105view_deps.t b/t/105view_deps.t index 2b8ccf2..21aa92b 100644 --- a/t/105view_deps.t +++ b/t/105view_deps.t @@ -5,31 +5,111 @@ use warnings; use Test::More; use Test::Exception; +use Test::Warn; use lib qw(t/lib); -use Devel::Dwarn; +use DBICTest; use ViewDeps; +use ViewDepsBad; BEGIN { - use_ok('DBIx::Class::ResultSource::View'); + require DBIx::Class; + plan skip_all => 'Test needs ' . + DBIx::Class::Optional::Dependencies->req_missing_for('deploy') + unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy'); } -my $view = DBIx::Class::ResultSource::View->new( { name => 'Upsilon' } ); -isa_ok( $view, 'DBIx::Class::ResultSource' ); -isa_ok( $view, 'DBIx::Class' ); +use_ok('DBIx::Class::ResultSource::View'); -can_ok( $view, $_ ) for qw/new from depends_on/; +#################### SANITY -diag( map {"$_\n"} @{ mro::get_linear_isa($view) } ); -#diag( DwarnS $view); +my $view = DBIx::Class::ResultSource::View->new; -my $schema = ViewDeps->connect; -ok($schema); +isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' ); +isa_ok( $view, 'DBIx::Class', 'A new view also' ); -#diag(DwarnS $schema); +can_ok( $view, $_ ) for qw/new from deploy_depends_on/; -#diag(DwarnS $schema->resultset('Bar')->result_source->depends_on); -diag keys %{$schema->resultset('Bar')->result_source->depends_on}; -my @dependencies = keys %{$schema->resultset('Bar')->result_source->depends_on}; -is($dependencies[0], 'mixin'); +#################### DEPS +{ + my $schema + = ViewDeps->connect( DBICTest->_database (quote_char => '"') ); + ok( $schema, 'Connected to ViewDeps schema OK' ); + +#################### DEPLOY + + $schema->deploy; + +#################### DOES ORDERING WORK? + + my $sqlt_object = $schema->{sqlt}; + + is_deeply( + [ map { $_->name } $sqlt_object->get_views ], + [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 + /], + "SQLT view order triumphantly matches our order." + ); + +#################### AND WHAT ABOUT USING THE SCHEMA? + + 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( DBICTest->_database ( quote_char => '"') ); + ok( $schema2, 'Connected to ViewDepsBad schema OK' ); + +#################### DEPLOY2 + + warnings_exist { $schema2->deploy } + [qr/no such table: main.aba_name_artists/], + "Deploying the bad schema produces a warning: aba_name_artists was not created."; + +#################### DOES ORDERING WORK 2? + + my $sqlt_object2 = $schema2->{sqlt}; + + is_deeply( + [ map { $_->name } $sqlt_object2->get_views ], + [qw/ + a_name_artists + track_number_fives + year_2010_cds + ab_name_artists + year_2010_cds_with_many_tracks + aba_name_artists_and_2010_cds_with_many_tracks + aba_name_artists + /], + "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 ] }; + + throws_ok { $schema2->resultset('AbaNameArtistsAnd2010CDsWithManyTracks')->next } + qr/no such table: aba_name_artists_and_2010_cds_with_many_tracks/, + "Query on AbaNameArtistsAnd2010CDsWithManyTracks throws, because the table does not exist" + ; +} done_testing;