Institute a central "load this first in testing" package
[dbsrgits/DBIx-Class.git] / t / prefetch / refined_search_on_relation.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
9ae300a4 3use strict;
4use warnings;
5
6use Test::More;
c0329273 7
9ae300a4 8use DBICTest;
9
10my $schema = DBICTest->init_schema();
11
12my $art = $schema->resultset('Artist')->find(
13 { 'me.artistid' => 1 },
14 { prefetch => 'cds', order_by => { -desc => 'cds.year' } }
15);
16
17is (
18 $art->cds->search({ year => 1999 })->next->year,
19 1999,
20 'Found expected CD with year 1999 after refined search',
21);
22
23is (
24 $art->cds->count({ year => 1999 }),
25 1,
26 'Correct refined count',
27);
28
29# this still should emit no queries:
49eeb48d 30$schema->is_executed_querycount( sub {
9ae300a4 31
32 my $cds = $art->cds;
33 is (
34 $cds->count,
35 3,
36 'Correct prefetched count',
37 );
38
39 my @years = qw(2001 1999 1997);
40 while (my $cd = $cds->next) {
41 is (
42 $cd->year,
43 (shift @years),
44 'Correct prefetched cd year',
45 );
46 }
47
49eeb48d 48}, 0, 'No queries on prefetched operations');
9ae300a4 49
50done_testing;