Commit | Line | Data |
70350518 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
a47e1233 |
8 | my $schema = DBICTest->init_schema(); |
0567538f |
9 | |
10 | BEGIN { |
11 | eval "use DBD::SQLite"; |
e60dc79f |
12 | plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 10); |
13 | } |
0567538f |
14 | |
15 | # test LIMIT |
f9db5527 |
16 | my $it = $schema->resultset("CD")->search( {}, |
0567538f |
17 | { rows => 3, |
18 | order_by => 'title' } |
19 | ); |
20 | is( $it->count, 3, "count ok" ); |
21 | is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" ); |
22 | $it->next; |
23 | $it->next; |
24 | is( $it->next, undef, "next past end of resultset ok" ); |
25 | |
26 | # test OFFSET |
f9db5527 |
27 | my @cds = $schema->resultset("CD")->search( {}, |
0567538f |
28 | { rows => 2, |
29 | offset => 2, |
30 | order_by => 'year' } |
31 | ); |
32 | is( $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 | ); |
40 | is( $it->count, 3, "software limit count ok" ); |
41 | is( $it->next->title, "Caterwaulin' Blues", "software iterator->next ok" ); |
42 | $it->next; |
43 | $it->next; |
44 | is( $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 | ); |
52 | is( $cds[0]->title, "Spoonful of bees", "software offset ok" ); |
53 | |
e60dc79f |
54 | |
55 | @cds = $schema->resultset("CD")->search( {}, |
56 | { |
57 | offset => 2, |
58 | order_by => 'year' } |
59 | ); |
60 | is( $cds[0]->title, "Spoonful of bees", "offset with no limit" ); |
61 | |
62 | |
0567538f |
63 | # based on a failing criteria submitted by waswas |
64 | # requires SQL::Abstract >= 1.20 |
f9db5527 |
65 | $it = $schema->resultset("CD")->search( |
0567538f |
66 | { title => [ |
67 | -and => |
68 | { |
69 | -like => '%bees' |
70 | }, |
71 | { |
72 | -not_like => 'Forkful%' |
73 | } |
74 | ] |
75 | }, |
76 | { rows => 5 } |
77 | ); |
78 | is( $it->count, 1, "complex abstract count ok" ); |
79 | |