File: grouped_pager.t

package info (click to toggle)
libdbix-class-perl 0.082844-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,320 kB
  • sloc: perl: 27,215; sql: 322; sh: 29; makefile: 16
file content (42 lines) | stat: -rw-r--r-- 936 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use strict;
use warnings;

use Test::More;

use lib qw(t/lib);

use DBICTest;

plan tests => 7;

my $schema = DBICTest->init_schema();

# add 2 extra artists
$schema->populate ('Artist', [
    [qw/name/],
    [qw/ar_1/],
    [qw/ar_2/],
]);

# add 3 extra cds to every artist
for my $ar ($schema->resultset ('Artist')->all) {
  for my $cdnum (1 .. 3) {
    $ar->create_related ('cds', {
      title => "bogon $cdnum",
      year => 2000 + $cdnum,
    });
  }
}

my $cds = $schema->resultset ('CD')->search ({}, { group_by => 'artist' } );
is ($cds->count, 5, 'Resultset collapses to 5 groups');

my ($pg1, $pg2, $pg3) = map { $cds->search_rs ({}, {rows => 2, page => $_}) } (1..3);

for ($pg1, $pg2, $pg3) {
  is ($_->pager->total_entries, 5, 'Total count via pager correct');
}

is ($pg1->count, 2, 'First page has 2 groups');
is ($pg2->count, 2, 'Second page has 2 groups');
is ($pg3->count, 1, 'Third page has one group remaining');