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