Commit | Line | Data |
70350518 |
1 | use strict; |
8273e845 |
2 | use warnings; |
70350518 |
3 | |
4 | use Test::More; |
038b8126 |
5 | use Test::Exception; |
70350518 |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
a47e1233 |
9 | my $schema = DBICTest->init_schema(); |
0567538f |
10 | |
0567538f |
11 | # test LIMIT |
f9db5527 |
12 | my $it = $schema->resultset("CD")->search( {}, |
0567538f |
13 | { rows => 3, |
14 | order_by => 'title' } |
15 | ); |
16 | is( $it->count, 3, "count ok" ); |
17 | is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" ); |
18 | $it->next; |
19 | $it->next; |
20 | is( $it->next, undef, "next past end of resultset ok" ); |
21 | |
22 | # test OFFSET |
f9db5527 |
23 | my @cds = $schema->resultset("CD")->search( {}, |
0567538f |
24 | { rows => 2, |
25 | offset => 2, |
26 | order_by => 'year' } |
27 | ); |
28 | is( $cds[0]->title, "Spoonful of bees", "offset ok" ); |
29 | |
30 | # test software-based limiting |
f9db5527 |
31 | $it = $schema->resultset("CD")->search( {}, |
0567538f |
32 | { rows => 3, |
33 | software_limit => 1, |
34 | order_by => 'title' } |
35 | ); |
36 | is( $it->count, 3, "software limit count ok" ); |
37 | is( $it->next->title, "Caterwaulin' Blues", "software iterator->next ok" ); |
38 | $it->next; |
39 | $it->next; |
40 | is( $it->next, undef, "software next past end of resultset ok" ); |
41 | |
f9db5527 |
42 | @cds = $schema->resultset("CD")->search( {}, |
0567538f |
43 | { rows => 2, |
44 | offset => 2, |
45 | software_limit => 1, |
46 | order_by => 'year' } |
47 | ); |
48 | is( $cds[0]->title, "Spoonful of bees", "software offset ok" ); |
49 | |
038b8126 |
50 | throws_ok { |
51 | $schema->resultset("CD")->search({}, { |
52 | rows => 2, |
53 | software_limit => 1, |
54 | })->as_query; |
55 | } qr/Unable to generate limited query representation with 'software_limit' enabled/; |
e60dc79f |
56 | |
57 | @cds = $schema->resultset("CD")->search( {}, |
58 | { |
59 | offset => 2, |
60 | order_by => 'year' } |
61 | ); |
62 | is( $cds[0]->title, "Spoonful of bees", "offset with no limit" ); |
63 | |
f9db5527 |
64 | $it = $schema->resultset("CD")->search( |
0567538f |
65 | { title => [ |
8273e845 |
66 | -and => |
0567538f |
67 | { |
68 | -like => '%bees' |
69 | }, |
70 | { |
71 | -not_like => 'Forkful%' |
72 | } |
73 | ] |
74 | }, |
75 | { rows => 5 } |
76 | ); |
77 | is( $it->count, 1, "complex abstract count ok" ); |
78 | |
56166f36 |
79 | done_testing; |