1use strict;
2use warnings;  
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8my $schema = DBICTest->init_schema();
9
10# test LIMIT
11my $it = $schema->resultset("CD")->search( {},
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
22my @cds = $schema->resultset("CD")->search( {},
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
30$it = $schema->resultset("CD")->search( {},
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
41@cds = $schema->resultset("CD")->search( {},
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
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
58# based on a failing criteria submitted by waswas
59# requires SQL::Abstract >= 1.20
60$it = $schema->resultset("CD")->search(
61    { title => [
62        -and => 
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
75done_testing;
76