Commit | Line | Data |
bccd177f |
1 | use strict; |
f549392f |
2 | use warnings; |
bccd177f |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
9 | my $schema = DBICTest->init_schema(); |
10 | |
1ee9aa72 |
11 | ## Real view |
3a8d32fa |
12 | my $cds_rs_2000 = $schema->resultset('CD')->search( { year => 2000 }); |
bccd177f |
13 | my $year2kcds_rs = $schema->resultset('Year2000CDs'); |
14 | |
3a8d32fa |
15 | is($cds_rs_2000->count, $year2kcds_rs->count, 'View Year2000CDs sees all CDs in year 2000'); |
bccd177f |
16 | |
17 | |
1ee9aa72 |
18 | ## Virtual view |
3a8d32fa |
19 | my $cds_rs_1999 = $schema->resultset('CD')->search( { year => 1999 }); |
1ee9aa72 |
20 | my $year1999cds_rs = $schema->resultset('Year1999CDs'); |
21 | |
3a8d32fa |
22 | is($cds_rs_1999->count, $year1999cds_rs->count, 'View Year1999CDs sees all CDs in year 1999'); |
1ee9aa72 |
23 | |
24 | |
f549392f |
25 | # Test if relationships work correctly |
26 | is_deeply ( |
27 | [ |
28 | $schema->resultset('Year1999CDs')->search ( |
29 | {}, |
30 | { |
31 | result_class => 'DBIx::Class::ResultClass::HashRefInflator', |
32 | prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ], |
33 | }, |
34 | )->all |
35 | ], |
36 | [ |
37 | $schema->resultset('CD')->search ( |
38 | { 'me.year' => '1999'}, |
39 | { |
40 | result_class => 'DBIx::Class::ResultClass::HashRefInflator', |
41 | prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ], |
42 | columns => [qw/cdid single_track title/], # to match the columns retrieved by the virtview |
43 | }, |
44 | )->all |
45 | ], |
46 | 'Prefetch over virtual view gives expected result', |
47 | ); |
1ee9aa72 |
48 | |
f549392f |
49 | is_deeply ( |
50 | [ |
51 | $schema->resultset('Year2000CDs')->search ( |
52 | {}, |
53 | { |
54 | result_class => 'DBIx::Class::ResultClass::HashRefInflator', |
55 | prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ], |
56 | }, |
57 | )->all |
58 | ], |
59 | [ |
60 | $schema->resultset('CD')->search ( |
61 | { 'me.year' => '2000'}, |
62 | { |
63 | result_class => 'DBIx::Class::ResultClass::HashRefInflator', |
64 | prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ], |
65 | }, |
66 | )->all |
67 | ], |
68 | 'Prefetch over regular view gives expected result', |
69 | ); |
bccd177f |
70 | |
f549392f |
71 | done_testing; |