Half way working stuff, needs a LOT of tweaking still
[dbsrgits/DBIx-Class.git] / t / prefetch / rows_bug.t
1 # Test to ensure we get a consistent result set wether or not we use the
2 # prefetch option in combination rows (LIMIT).
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use lib qw(t/lib);
8 use DBICTest;
9
10 plan skip_all => 'fix pending';
11 #plan tests => 4;
12
13 my $schema = DBICTest->init_schema();
14 my $no_prefetch = $schema->resultset('Artist')->search(
15   undef,
16   { rows => 3 }
17 );
18
19 my $use_prefetch = $schema->resultset('Artist')->search(
20   undef,
21   {
22     prefetch => 'cds',
23     rows     => 3
24   }
25 );
26
27 is($no_prefetch->count, $use_prefetch->count, '$no_prefetch->count == $use_prefetch->count');
28 is(
29   scalar ($no_prefetch->all),
30   scalar ($use_prefetch->all),
31   "Amount of returned rows is right"
32 );
33
34
35
36 my $artist_many_cds = $schema->resultset('Artist')->search ( {}, {
37   join => 'cds',
38   group_by => 'me.artistid',
39   having => \ 'count(cds.cdid) > 1',
40 })->first;
41
42
43 $no_prefetch = $schema->resultset('Artist')->search(
44   { artistid => $artist_many_cds->id },
45   { rows => 1 }
46 );
47
48 $use_prefetch = $schema->resultset('Artist')->search(
49   { artistid => $artist_many_cds->id },
50   {
51     prefetch => 'cds',
52     rows     => 1
53   }
54 );
55
56 my $prefetch_artist = $use_prefetch->first;
57 my $normal_artist = $no_prefetch->first;
58
59 is(
60   $prefetch_artist->cds->count,
61   $normal_artist->cds->count,
62   "Count of child rel with prefetch + rows => 1 is right"
63 );
64 is (
65   scalar ($prefetch_artist->cds->all),
66   scalar ($normal_artist->cds->all),
67   "Amount of child rel rows with prefetch + rows => 1 is right"
68 );