fix and regression test for RT #62642
[dbsrgits/DBIx-Class.git] / t / 75limit.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my $schema = DBICTest->init_schema();
9
10 # test LIMIT
11 my $it = $schema->resultset("CD")->search( {},
12     { rows => 3,
13       order_by => 'title' }
14 );
15 is( $it->count, 3, "count ok" );
16 is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
17 $it->next;
18 $it->next;
19 is( $it->next, undef, "next past end of resultset ok" );
20
21 # test OFFSET
22 my @cds = $schema->resultset("CD")->search( {},
23     { rows => 2,
24       offset => 2,
25       order_by => 'year' }
26 );
27 is( $cds[0]->title, "Spoonful of bees", "offset ok" );
28
29 # test software-based limiting
30 $it = $schema->resultset("CD")->search( {},
31     { rows => 3,
32       software_limit => 1,
33       order_by => 'title' }
34 );
35 is( $it->count, 3, "software limit count ok" );
36 is( $it->next->title, "Caterwaulin' Blues", "software iterator->next ok" );
37 $it->next;
38 $it->next;
39 is( $it->next, undef, "software next past end of resultset ok" );
40
41 @cds = $schema->resultset("CD")->search( {},
42     { rows => 2,
43       offset => 2,
44       software_limit => 1,
45       order_by => 'year' }
46 );
47 is( $cds[0]->title, "Spoonful of bees", "software offset ok" );
48
49
50 @cds = $schema->resultset("CD")->search( {},
51     {
52       offset => 2,
53       order_by => 'year' }
54 );
55 is( $cds[0]->title, "Spoonful of bees", "offset with no limit" );
56
57
58 # based on a failing criteria submitted by waswas
59 # requires SQL::Abstract >= 1.20
60 $it = $schema->resultset("CD")->search(
61     { title => [
62         -and => 
63             {
64                 -like => '%bees'
65             },
66             {
67                 -not_like => 'Forkful%'
68             }
69         ]
70     },
71     { rows => 5 }
72 );
73 is( $it->count, 1, "complex abstract count ok" );
74
75 done_testing;