X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F104view.t;h=a13ea00e5fa0145ee8a763cfc19312290fc13de6;hb=people%2Fabraxxa%2Fhas_relationship_loaded;hp=3efdcf1074c83c169d69f2f5da25ca71acdfc2dc;hpb=3a8d32fa8cf04b32b4c6fd2524b255b50eccda9f;p=dbsrgits%2FDBIx-Class.git diff --git a/t/104view.t b/t/104view.t index 3efdcf1..a13ea00 100644 --- a/t/104view.t +++ b/t/104view.t @@ -1,15 +1,12 @@ 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 => 2; - ## Real view my $cds_rs_2000 = $schema->resultset('CD')->search( { year => 2000 }); my $year2kcds_rs = $schema->resultset('Year2000CDs'); @@ -24,5 +21,50 @@ 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/] } ], + }, + )->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 + }, + )->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;