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