fix test bug, also: fuck you, multi create
[dbsrgits/DBIx-Class-Historic.git] / t / 75limit.t
CommitLineData
70350518 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
a47e1233 8my $schema = DBICTest->init_schema();
0567538f 9
10BEGIN {
11 eval "use DBD::SQLite";
e60dc79f 12 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 10);
13}
0567538f 14
15# test LIMIT
f9db5527 16my $it = $schema->resultset("CD")->search( {},
0567538f 17 { rows => 3,
18 order_by => 'title' }
19);
20is( $it->count, 3, "count ok" );
21is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
22$it->next;
23$it->next;
24is( $it->next, undef, "next past end of resultset ok" );
25
26# test OFFSET
f9db5527 27my @cds = $schema->resultset("CD")->search( {},
0567538f 28 { rows => 2,
29 offset => 2,
30 order_by => 'year' }
31);
32is( $cds[0]->title, "Spoonful of bees", "offset ok" );
33
34# test software-based limiting
f9db5527 35$it = $schema->resultset("CD")->search( {},
0567538f 36 { rows => 3,
37 software_limit => 1,
38 order_by => 'title' }
39);
40is( $it->count, 3, "software limit count ok" );
41is( $it->next->title, "Caterwaulin' Blues", "software iterator->next ok" );
42$it->next;
43$it->next;
44is( $it->next, undef, "software next past end of resultset ok" );
45
f9db5527 46@cds = $schema->resultset("CD")->search( {},
0567538f 47 { rows => 2,
48 offset => 2,
49 software_limit => 1,
50 order_by => 'year' }
51);
52is( $cds[0]->title, "Spoonful of bees", "software offset ok" );
53
e60dc79f 54
55@cds = $schema->resultset("CD")->search( {},
56 {
57 offset => 2,
58 order_by => 'year' }
59);
60is( $cds[0]->title, "Spoonful of bees", "offset with no limit" );
61
62
0567538f 63# based on a failing criteria submitted by waswas
64# requires SQL::Abstract >= 1.20
f9db5527 65$it = $schema->resultset("CD")->search(
0567538f 66 { title => [
67 -and =>
68 {
69 -like => '%bees'
70 },
71 {
72 -not_like => 'Forkful%'
73 }
74 ]
75 },
76 { rows => 5 }
77);
78is( $it->count, 1, "complex abstract count ok" );
79