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