X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F104view.t;h=a3668b2b40c05409397c43c9308acbb15c18e842;hb=HEAD;hp=f800af45fe89f99c4c48373e8a90c37f074d6339;hpb=bccd177fabb721d4edf637c0b5024737b6705edb;p=dbsrgits%2FDBIx-Class.git diff --git a/t/104view.t b/t/104view.t index f800af4..a3668b2 100644 --- a/t/104view.t +++ b/t/104view.t @@ -1,19 +1,74 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use strict; -use warnings; +use warnings; use Test::More; -use Test::Exception; -use lib qw(t/lib); + use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 1; - -my $cds_rs = $schema->resultset('CD')->search( { year => 2000 }); +## Real view +my $cds_rs_2000 = $schema->resultset('CD')->search( { year => 2000 }); my $year2kcds_rs = $schema->resultset('Year2000CDs'); -is($cds_rs->count, $year2kcds_rs->count, 'View Year2000CDs sees all CDs in year 2000'); +is($cds_rs_2000->count, $year2kcds_rs->count, 'View Year2000CDs sees all CDs in year 2000'); + + +## Virtual view +my $cds_rs_1999 = $schema->resultset('CD')->search( { year => 1999 }); +my $year1999cds_rs = $schema->resultset('Year1999CDs'); + +is($cds_rs_1999->count, $year1999cds_rs->count, 'View Year1999CDs sees all CDs in year 1999'); + +# Test if relationships work correctly +is_deeply ( + [ + $schema->resultset('Year1999CDs')->search ( + {}, + { + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ], + order_by => 'tracks.trackid', + }, + )->all + ], + [ + $schema->resultset('CD')->search ( + { 'me.year' => '1999'}, + { + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ], + columns => [qw/cdid single_track title/], # to match the columns retrieved by the virtview + order_by => 'tracks.trackid', + }, + )->all + ], + 'Prefetch over virtual view gives expected result', +); +is_deeply ( + [ + $schema->resultset('Year2000CDs')->search ( + {}, + { + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ], + }, + )->all + ], + [ + $schema->resultset('CD')->search ( + { 'me.year' => '2000'}, + { + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ], + }, + )->all + ], + 'Prefetch over regular view gives expected result', +); +done_testing;