Trailing WS crusade - got to save them bits
[dbsrgits/DBIx-Class.git] / t / 75limit.t
CommitLineData
70350518 1use strict;
8273e845 2use warnings;
70350518 3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
a47e1233 8my $schema = DBICTest->init_schema();
0567538f 9
0567538f 10# test LIMIT
f9db5527 11my $it = $schema->resultset("CD")->search( {},
0567538f 12 { rows => 3,
13 order_by => 'title' }
14);
15is( $it->count, 3, "count ok" );
16is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
17$it->next;
18$it->next;
19is( $it->next, undef, "next past end of resultset ok" );
20
21# test OFFSET
f9db5527 22my @cds = $schema->resultset("CD")->search( {},
0567538f 23 { rows => 2,
24 offset => 2,
25 order_by => 'year' }
26);
27is( $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);
35is( $it->count, 3, "software limit count ok" );
36is( $it->next->title, "Caterwaulin' Blues", "software iterator->next ok" );
37$it->next;
38$it->next;
39is( $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);
47is( $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);
55is( $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 => [
8273e845 62 -and =>
0567538f 63 {
64 -like => '%bees'
65 },
66 {
67 -not_like => 'Forkful%'
68 }
69 ]
70 },
71 { rows => 5 }
72);
73is( $it->count, 1, "complex abstract count ok" );
74
56166f36 75done_testing;