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