Removed BasicRels and reorganized where the various init/setup code resides.
[dbsrgits/DBIx-Class.git] / t / run / 15limit.tl
CommitLineData
0567538f 1sub run_tests {
1edaf6fe 2my $schema = shift;
0567538f 3
4BEGIN {
5 eval "use DBD::SQLite";
6 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 9);
7}
8
9# test LIMIT
f9db5527 10my $it = $schema->resultset("CD")->search( {},
0567538f 11 { rows => 3,
12 order_by => 'title' }
13);
14is( $it->count, 3, "count ok" );
15is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
16$it->next;
17$it->next;
18is( $it->next, undef, "next past end of resultset ok" );
19
20# test OFFSET
f9db5527 21my @cds = $schema->resultset("CD")->search( {},
0567538f 22 { rows => 2,
23 offset => 2,
24 order_by => 'year' }
25);
26is( $cds[0]->title, "Spoonful of bees", "offset ok" );
27
28# test software-based limiting
f9db5527 29$it = $schema->resultset("CD")->search( {},
0567538f 30 { rows => 3,
31 software_limit => 1,
32 order_by => 'title' }
33);
34is( $it->count, 3, "software limit count ok" );
35is( $it->next->title, "Caterwaulin' Blues", "software iterator->next ok" );
36$it->next;
37$it->next;
38is( $it->next, undef, "software next past end of resultset ok" );
39
f9db5527 40@cds = $schema->resultset("CD")->search( {},
0567538f 41 { rows => 2,
42 offset => 2,
43 software_limit => 1,
44 order_by => 'year' }
45);
46is( $cds[0]->title, "Spoonful of bees", "software offset ok" );
47
48# based on a failing criteria submitted by waswas
49# requires SQL::Abstract >= 1.20
f9db5527 50$it = $schema->resultset("CD")->search(
0567538f 51 { title => [
52 -and =>
53 {
54 -like => '%bees'
55 },
56 {
57 -not_like => 'Forkful%'
58 }
59 ]
60 },
61 { rows => 5 }
62);
63is( $it->count, 1, "complex abstract count ok" );
64
65}
66
671;