(travis) Remove makefile fixup, now hardcoded in the subrepo
[dbsrgits/DBIx-Class.git] / t / count / joined.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use DBICTest;
8
9 my $schema = DBICTest->init_schema();
10
11 my $cds = $schema->resultset("CD")->search({ cdid => 1 }, { join => { cd_to_producer => 'producer' } });
12 cmp_ok($cds->count, '>', 1, "extra joins explode entity count");
13
14 for my $arg (
15   [ 'prefetch-collapsed has_many' => { prefetch => 'cd_to_producer' } ],
16   [ 'distict-collapsed result' => { distinct => 1 } ],
17   [ 'explicit collapse request' => { collapse => 1 } ],
18 ) {
19   for my $hri (0,1) {
20     my $diag = $arg->[0] . ($hri ? ' with HRI' : '');
21
22     my $rs = $cds->search({}, {
23       %{$arg->[1]},
24       $hri ? ( result_class => 'DBIx::Class::ResultClass::HashRefInflator' ) : (),
25     });
26
27     is
28       $rs->count,
29       1,
30       "Count correct on $diag",
31     ;
32
33     is
34       scalar $rs->all,
35       1,
36       "Amount of constructed objects matches count on $diag",
37     ;
38   }
39 }
40
41 # JOIN and LEFT JOIN issues mean that we've seen problems where counted rows and fetched rows are sometimes 1 higher than they should
42 # be in the related resultset.
43 my $artist=$schema->resultset('Artist')->create({name => 'xxx'});
44 is($artist->related_resultset('cds')->count(), 0, "No CDs found for a shiny new artist");
45 is(scalar($artist->related_resultset('cds')->all()), 0, "No CDs fetched for a shiny new artist");
46
47 my $artist_rs = $schema->resultset('Artist')->search({artistid => $artist->id});
48 is($artist_rs->related_resultset('cds')->count(), 0, "No CDs counted for a shiny new artist using a resultset search");
49 is(scalar($artist_rs->related_resultset('cds')->all), 0, "No CDs fetched for a shiny new artist using a resultset search");
50
51 done_testing;