fix Cursor SYNOPSIS
[dbsrgits/DBIx-Class-Historic.git] / t / 104view.t
CommitLineData
bccd177f 1use strict;
f549392f 2use warnings;
bccd177f 3
4use Test::More;
bccd177f 5use lib qw(t/lib);
6use DBICTest;
7
8my $schema = DBICTest->init_schema();
9
1ee9aa72 10## Real view
3a8d32fa 11my $cds_rs_2000 = $schema->resultset('CD')->search( { year => 2000 });
bccd177f 12my $year2kcds_rs = $schema->resultset('Year2000CDs');
13
3a8d32fa 14is($cds_rs_2000->count, $year2kcds_rs->count, 'View Year2000CDs sees all CDs in year 2000');
bccd177f 15
16
1ee9aa72 17## Virtual view
3a8d32fa 18my $cds_rs_1999 = $schema->resultset('CD')->search( { year => 1999 });
1ee9aa72 19my $year1999cds_rs = $schema->resultset('Year1999CDs');
20
3a8d32fa 21is($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
25is_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);
1ee9aa72 47
f549392f 48is_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);
bccd177f 69
f549392f 70done_testing;