better money value comparison in tests
[dbsrgits/DBIx-Class.git] / t / count / grouped_pager.t
CommitLineData
db326a59 1use strict;
2use warnings;
3
4use Test::More;
5
6use lib qw(t/lib);
7
8use DBICTest;
9
10plan tests => 7;
11
12my $schema = DBICTest->init_schema();
13
14use Data::Dumper;
15
16# add 2 extra artists
17$schema->populate ('Artist', [
18 [qw/name/],
19 [qw/ar_1/],
20 [qw/ar_2/],
21]);
22
23# add 3 extra cds to every artist
24for my $ar ($schema->resultset ('Artist')->all) {
25 for my $cdnum (1 .. 3) {
26 $ar->create_related ('cds', {
27 title => "bogon $cdnum",
28 year => 2000 + $cdnum,
29 });
30 }
31}
32
33my $cds = $schema->resultset ('CD')->search ({}, { group_by => 'artist' } );
34is ($cds->count, 5, 'Resultset collapses to 5 groups');
35
36my ($pg1, $pg2, $pg3) = map { $cds->search_rs ({}, {rows => 2, page => $_}) } (1..3);
37
38for ($pg1, $pg2, $pg3) {
39 is ($_->pager->total_entries, 5, 'Total count via pager correct');
40}
41
42is ($pg1->count, 2, 'First page has 2 groups');
43is ($pg2->count, 2, 'Second page has 2 groups');
44is ($pg3->count, 1, 'Third page has one group remaining');