Commit | Line | Data |
0567538f |
1 | sub run_tests { |
1edaf6fe |
2 | my $schema = shift; |
0567538f |
3 | |
4 | BEGIN { |
5 | eval "use DBD::SQLite"; |
6 | plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 9); |
7 | } |
8 | |
9 | # test LIMIT |
f9db5527 |
10 | my $it = $schema->resultset("CD")->search( {}, |
0567538f |
11 | { rows => 3, |
12 | order_by => 'title' } |
13 | ); |
14 | is( $it->count, 3, "count ok" ); |
15 | is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" ); |
16 | $it->next; |
17 | $it->next; |
18 | is( $it->next, undef, "next past end of resultset ok" ); |
19 | |
20 | # test OFFSET |
f9db5527 |
21 | my @cds = $schema->resultset("CD")->search( {}, |
0567538f |
22 | { rows => 2, |
23 | offset => 2, |
24 | order_by => 'year' } |
25 | ); |
26 | is( $cds[0]->title, "Spoonful of bees", "offset ok" ); |
27 | |
28 | # test software-based limiting |
f9db5527 |
29 | $it = $schema->resultset("CD")->search( {}, |
0567538f |
30 | { rows => 3, |
31 | software_limit => 1, |
32 | order_by => 'title' } |
33 | ); |
34 | is( $it->count, 3, "software limit count ok" ); |
35 | is( $it->next->title, "Caterwaulin' Blues", "software iterator->next ok" ); |
36 | $it->next; |
37 | $it->next; |
38 | is( $it->next, undef, "software next past end of resultset ok" ); |
39 | |
f9db5527 |
40 | @cds = $schema->resultset("CD")->search( {}, |
0567538f |
41 | { rows => 2, |
42 | offset => 2, |
43 | software_limit => 1, |
44 | order_by => 'year' } |
45 | ); |
46 | is( $cds[0]->title, "Spoonful of bees", "software offset ok" ); |
47 | |
48 | # based on a failing criteria submitted by waswas |
49 | # requires SQL::Abstract >= 1.20 |
f9db5527 |
50 | $it = $schema->resultset("CD")->search( |
0567538f |
51 | { title => [ |
52 | -and => |
53 | { |
54 | -like => '%bees' |
55 | }, |
56 | { |
57 | -not_like => 'Forkful%' |
58 | } |
59 | ] |
60 | }, |
61 | { rows => 5 } |
62 | ); |
63 | is( $it->count, 1, "complex abstract count ok" ); |
64 | |
65 | } |
66 | |
67 | 1; |