Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / sqlmaker / limit_dialects / basic.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
70350518 3use strict;
8273e845 4use warnings;
70350518 5
6use Test::More;
038b8126 7use Test::Exception;
c0329273 8
70350518 9use DBICTest;
10
a47e1233 11my $schema = DBICTest->init_schema();
0567538f 12
0567538f 13# test LIMIT
f9db5527 14my $it = $schema->resultset("CD")->search( {},
0567538f 15 { rows => 3,
16 order_by => 'title' }
17);
18is( $it->count, 3, "count ok" );
19is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
20$it->next;
21$it->next;
22is( $it->next, undef, "next past end of resultset ok" );
23
24# test OFFSET
f9db5527 25my @cds = $schema->resultset("CD")->search( {},
0567538f 26 { rows => 2,
27 offset => 2,
28 order_by => 'year' }
29);
30is( $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);
38is( $it->count, 3, "software limit count ok" );
39is( $it->next->title, "Caterwaulin' Blues", "software iterator->next ok" );
40$it->next;
41$it->next;
42is( $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);
50is( $cds[0]->title, "Spoonful of bees", "software offset ok" );
51
038b8126 52throws_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);
64is( $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);
79is( $it->count, 1, "complex abstract count ok" );
80
56166f36 81done_testing;