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