+BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
+
use strict;
use warnings;
use Test::More;
-use Test::Exception;
-use lib qw(t/lib);
+
use DBICTest;
my $schema = DBICTest->init_schema();
{ order_by => 'title',
rows => 3 }
);
-my $page = $it->page(2);
-is( $page->count, 2, "standard resultset paged rs count ok" );
+{
+ my $page = $it->page(2);
-is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" );
+ is( $page->count, 2, "standard resultset paged rs count ok" );
+ is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" );
+}
# test software-based limit paging
$it = $rs->search(
});
my $row = $rs->search({}, {
- order_by => 'cdid',
+ order_by => 'cdid',
offset => 3,
rows => 1
})->single;
# test cached resultsets
my $init_cnt = $rs->count;
-$it = $rs->search({}, { rows => 3, cache => 1 })->page(3);
+$it = $rs->search({}, { rows => 3, cache => 1 })->page(2);
+is ($it->count, 3, '3 rows');
+is (scalar $it->all, 3, '3 objects');
+
+isa_ok($it->pager,'Data::Page','Get a pager back ok');
+is($it->pager->total_entries,7);
+is($it->pager->current_page,2);
+is($it->pager->entries_on_this_page,3);
+
+$it = $it->page(3);
is ($it->count, 1, 'One row');
is (scalar $it->all, 1, 'One object');
+isa_ok($it->pager,'Data::Page','Get a pager back ok');
+is($it->pager->total_entries,7);
+is($it->pager->current_page,3);
+is($it->pager->entries_on_this_page,1);
+
+
$it->delete;
is ($rs->count, $init_cnt - 1, 'One row deleted as expected');
is ($it->count, 1, 'One row (cached)');
is (scalar $it->all, 1, 'One object (cached)');
-throws_ok { $it->pager }
- qr/Pagers on cached resultsets are not supported/, 'No pagers on cached resultsets';
-
# test fresh rs creation with modified defaults
my $p = sub { $schema->resultset('CD')->page(1)->pager->entries_per_page; };
is($p->(), 5, 'default rows is 5');
+# does serialization work (preserve laziness, while preserving state if exits)
+$qcnt = 0;
+$it = $rs->search(
+ {},
+ { order_by => 'title',
+ rows => 5,
+ page => 2 }
+);
+$pager = $it->pager;
+is ($qcnt, 0, 'No queries on rs/pager creation');
+
+# test *requires* it to be Storable
+$it = do {
+ local $DBIx::Class::ResultSourceHandle::thaw_schema = $schema;
+ Storable::dclone ($it);
+};
+is ($qcnt, 0, 'No queries on rs/pager freeze/thaw');
+
+is( $it->pager->entries_on_this_page, 1, "entries_on_this_page ok for page 2" );
+
+is ($qcnt, 1, 'Count fired to get pager page entries');
+
+$rs->create({ title => 'bah', artist => 1, year => 2011 });
+
+$qcnt = 0;
+# test *requires* it to be Storable
+$it = do {
+ local $DBIx::Class::ResultSourceHandle::thaw_schema = $schema;
+ Storable::dclone ($it);
+};
+is ($qcnt, 0, 'No queries on rs/pager freeze/thaw');
+
+is( $it->pager->entries_on_this_page, 1, "entries_on_this_page ok for page 2, even though underlying count changed" );
+
+is ($qcnt, 0, 'No count fired on pre-existing total count');
done_testing;