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