[Bps-public-commit] dbix-searchbuilder branch, master, updated. 53ab26f57d44a25193e6158638235401160affee
Ruslan Zakirov
ruz at bestpractical.com
Mon Mar 22 20:28:45 EDT 2010
The branch, master has been updated
via 53ab26f57d44a25193e6158638235401160affee (commit)
via b8032226bc1f0eb30cce56bb81454a2a3c3fde51 (commit)
via 9df72585e318ecc586a639a4e15f37c298c00f10 (commit)
via e083f5719345d51e34f2c271809b3e7c67ced259 (commit)
via 71dd55a8e4732d2a9796bc84de0fe432403347cf (commit)
from 39129fa966516b891b7bba660365f75777e97c47 (commit)
Summary of changes:
Changes | 10 +++++++
SearchBuilder.pm | 14 +++++++----
t/01searches.t | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 88 insertions(+), 7 deletions(-)
- Log -----------------------------------------------------------------
commit 71dd55a8e4732d2a9796bc84de0fe432403347cf
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Mon Mar 22 23:20:41 2010 +0300
force RedoSearch if page size changed
diff --git a/SearchBuilder.pm b/SearchBuilder.pm
index d13a796..0918360 100755
--- a/SearchBuilder.pm
+++ b/SearchBuilder.pm
@@ -1229,7 +1229,11 @@ Returns the current page size.
sub RowsPerPage {
my $self = shift;
- $self->{'show_rows'} = shift if (@_);
+
+ if ( @_ && ($_[0]||0) != $self->{'show_rows'} ) {
+ $self->{'show_rows'} = shift || 0;
+ $self->RedoSearch;
+ }
return ( $self->{'show_rows'} );
}
commit e083f5719345d51e34f2c271809b3e7c67ced259
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Tue Mar 23 01:51:38 2010 +0300
don't RedoSearch when FirstRow is set to the same value
diff --git a/SearchBuilder.pm b/SearchBuilder.pm
index 0918360..5a5faad 100755
--- a/SearchBuilder.pm
+++ b/SearchBuilder.pm
@@ -1304,7 +1304,7 @@ methods to walk pages. It only may be helpful to get 10 records starting from
sub FirstRow {
my $self = shift;
- if (@_) {
+ if (@_ && ($_[0]||1) != ($self->{'first_row'}+1) ) {
$self->{'first_row'} = shift;
#SQL starts counting at 0
commit 9df72585e318ecc586a639a4e15f37c298c00f10
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Tue Mar 23 01:52:42 2010 +0300
fix very long standing bug in NextPage and PrevPage
diff --git a/SearchBuilder.pm b/SearchBuilder.pm
index 5a5faad..ca6e801 100755
--- a/SearchBuilder.pm
+++ b/SearchBuilder.pm
@@ -1246,7 +1246,7 @@ Turns one page forward.
sub NextPage {
my $self = shift;
- $self->FirstRow( $self->FirstRow + $self->RowsPerPage );
+ $self->FirstRow( $self->FirstRow + 1 + $self->RowsPerPage );
}
=head3 PrevPage
@@ -1257,8 +1257,8 @@ Turns one page backwards.
sub PrevPage {
my $self = shift;
- if ( ( $self->FirstRow - $self->RowsPerPage ) > 1 ) {
- $self->FirstRow( $self->FirstRow - $self->RowsPerPage );
+ if ( ( $self->FirstRow - $self->RowsPerPage ) > 0 ) {
+ $self->FirstRow( 1 + $self->FirstRow - $self->RowsPerPage );
}
else {
$self->FirstRow(1);
commit b8032226bc1f0eb30cce56bb81454a2a3c3fde51
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Tue Mar 23 01:53:12 2010 +0300
test pages walking
diff --git a/t/01searches.t b/t/01searches.t
index b1e5fb5..285035d 100644
--- a/t/01searches.t
+++ b/t/01searches.t
@@ -7,7 +7,7 @@ use Test::More;
BEGIN { require "t/utils.pl" }
our (@AvailableDrivers);
-use constant TESTS_PER_DRIVER => 78;
+use constant TESTS_PER_DRIVER => 105;
my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
plan tests => $total;
@@ -212,13 +212,80 @@ SKIP: {
# RowsPerPage(0)
# https://rt.cpan.org/Ticket/Display.html?id=42988
$users_obj->CleanSlate;
+ is_deeply( $users_obj, $clean_obj, 'after CleanSlate looks like new object');
$users_obj->UnLimit;
$users_obj->RowsPerPage(0);
is( $users_obj->Count, $count_all, "found all users" );
- ok( $users_obj->First, "fetched first users" );
+ ok( $users_obj->First, "fetched first user" );
+ # walk all pages
$users_obj->CleanSlate;
is_deeply( $users_obj, $clean_obj, 'after CleanSlate looks like new object');
+ $users_obj->UnLimit;
+ $users_obj->OrderBy(FIELD => 'Login');
+ $users_obj->RowsPerPage(2);
+ {
+ my %seen;
+ my $saw_on_page = 0;
+ my $pages = 0;
+ my $prev_login = '';
+ do {
+ $saw_on_page = 0;
+ while ( my $user = $users_obj->Next ) {
+ $saw_on_page++;
+ $seen{ $user->id }++;
+ ok( $prev_login lt $user->Login, "order is correct" );
+ }
+ last unless $saw_on_page;
+
+ $pages++;
+ if ( $pages * 2 <= $count_all ) {
+ is( $saw_on_page, 2, "saw only two on the page" );
+ } else {
+ is( $saw_on_page, $count_all - ($pages * 2), "saw slightly less users on the last page");
+ }
+ $users_obj->NextPage;
+ } while ( $saw_on_page );
+
+ ok( !grep( $_ != 1, values %seen ), "saw each user only once") or do { use Data::Dumper; diag Dumper(\%seen) };
+ is( scalar keys %seen, $count_all, "saw all users" )
+ }
+
+ # two steps forward, on step back
+ $users_obj = TestApp::Users->new( $handle );
+ $users_obj->UnLimit;
+ $users_obj->OrderBy(FIELD => 'Login');
+ $users_obj->RowsPerPage(1);
+ for ( 1 .. $count_all-1) {
+ my $u = $users_obj->Next;
+ ok( $u, "got a user");
+ ok(!$users_obj->Next, "only on the page");
+
+ $users_obj->NextPage;
+ isnt( $users_obj->Next->id, $u->id, "got a user and he is different");
+ ok(!$users_obj->Next, "only on the page");
+
+ $users_obj->PrevPage;
+ is( $users_obj->Next->id, $u->id, "got a user and he is the same");
+ ok(!$users_obj->Next, "only on the page");
+
+ $users_obj->NextPage;
+ }
+
+ # tricky variant: skip 1, but show 2
+ $users_obj = TestApp::Users->new( $handle );
+ $users_obj->UnLimit;
+ $users_obj->OrderBy(FIELD => 'Login');
+ $users_obj->RowsPerPage(2);
+ $users_obj->FirstRow(2);
+ {
+ my $u = $users_obj->Next;
+ is( $u->Login, 'cubic', "cubic is second in the list");
+ }
+ {
+ my $u = $users_obj->Next;
+ is( $u->Login, 'glasser', "glasser is third in the list");
+ }
cleanup_schema( 'TestApp', $handle );
}} # SKIP, foreach blocks
commit 53ab26f57d44a25193e6158638235401160affee
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Tue Mar 23 03:28:39 2010 +0300
update Changelog
diff --git a/Changes b/Changes
index 0e6aab8..8d2126e 100755
--- a/Changes
+++ b/Changes
@@ -2,8 +2,18 @@ Revision history for Perl extension DBIx::SearchBuilder.
1.57
+* INCOMPATIBLE CHANGE: NextPage and PrevPage were addind rows from
+ previouse page. Long standing issue, back at those times Jesse
+ was 20 years old and thought that it's good idea.
+* RedoSearch when RowsPerPage is changed
+* don't RedoSearch if FirstRow is called, but is not changed
+ actually
+* document all paging functions and test them
+* make debugging problems easier by passing errors back
+ https://rt.cpan.org/Ticket/Display.html?id=55203
* fix Record->PrimaryKeys, field names in values hash are lc'ed
https://rt.cpan.org/Ticket/Display.html?id=18280
+* doc updates and cleanups
1.56 Fri Jul 17 02:05:32 MSD 2009
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list