Made pager a method on ResultSet, added rs->page(num) to page an ordinary RS, made...
[dbsrgits/DBIx-Class.git] / t / 15limit.t
1 use strict;
2 use Test::More;
3
4 BEGIN {
5     eval "use DBD::SQLite";
6     plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 6);
7 }                                                                               
8
9 use lib qw(t/lib);
10
11 use_ok('DBICTest');
12
13 # test LIMIT
14 my $it = DBICTest::CD->search( {},
15     { rows => 3,
16       order_by => 'title' }
17 );
18 is( $it->count, 3, "count ok" );
19 is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
20 $it->next;
21 $it->next;
22 is( $it->next, undef, "next past end of resultset ok" );
23
24 # test OFFSET
25 my @cds = DBICTest::CD->search( {},
26     { rows => 2,
27       offset => 2,
28       order_by => 'year' }
29 );
30 is( $cds[0]->title, "Spoonful of bees", "offset ok" );
31
32 # based on a failing criteria submitted by waswas
33 # requires SQL::Abstract >= 1.20
34 $it = DBICTest::CD->search(
35     { title => [
36         -and => 
37             {
38                 -like => '%bees'
39             },
40             {
41                 -not_like => 'Forkful%'
42             }
43         ]
44     },
45     { rows => 5 }
46 );
47 is( $it->count, 1, "complex abstract count ok" );