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