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 | |
0567538f |
10 | # test LIMIT |
f9db5527 |
11 | my $it = $schema->resultset("CD")->search( {}, |
0567538f |
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 |
f9db5527 |
22 | my @cds = $schema->resultset("CD")->search( {}, |
0567538f |
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 |
f9db5527 |
30 | $it = $schema->resultset("CD")->search( {}, |
0567538f |
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 | |
f9db5527 |
41 | @cds = $schema->resultset("CD")->search( {}, |
0567538f |
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 | |
e60dc79f |
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 | |
0567538f |
58 | # based on a failing criteria submitted by waswas |
59 | # requires SQL::Abstract >= 1.20 |
f9db5527 |
60 | $it = $schema->resultset("CD")->search( |
0567538f |
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 | |
56166f36 |
75 | done_testing; |