Bug 19209: Add ->is_paged method to Koha::Objects
authorTomas Cohen Arazi <tomascohen@theke.io>
Wed, 30 Aug 2017 15:09:37 +0000 (12:09 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 1 Sep 2017 16:00:06 +0000 (13:00 -0300)
This patch adds ->is_paged to Koha::Objects. It is inherited from the underlying resultset
from DBIC so there's no code besides adding it to the known methods in AUTOLOAD.

Tests are added for the newly exported method.

To test:
- Apply this patch
- Run:
  $ sudo koha-shell kohadev
 k$ cd kohaclone
 k$ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass!
- Sign off :-D

Sponsored-by: Camden County
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Objects.pm
t/db_dependent/Koha/Objects.t

index 193e494..8c79afd 100644 (file)
@@ -379,7 +379,7 @@ Currently count, pager, update and delete are covered.
 sub AUTOLOAD {
     my ( $self, @params ) = @_;
 
-    my @known_methods = qw( count pager update delete result_class single slice );
+    my @known_methods = qw( count is_paged pager update delete result_class single slice );
     my $method = our $AUTOLOAD;
     $method =~ s/.*:://;
 
index c05afc3..b382ce1 100644 (file)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 15;
+use Test::More tests => 16;
 use Test::Warn;
 
 use Koha::Authority::Types;
@@ -214,3 +214,21 @@ subtest 'Exceptions' => sub {
 };
 
 $schema->storage->txn_rollback;
+
+subtest '->is_paged tests' => sub {
+
+    plan tests => 2;
+
+    $schema->storage->txn_begin;
+
+    foreach (1..10) {
+        $builder->build_object({ class => 'Koha::Patrons' });
+    }
+
+    my $patrons = Koha::Patrons->search();
+    ok( !$patrons->is_paged, 'Search is not paged' );
+    $patrons = Koha::Patrons->search( undef, { 'page' => 1, 'rows' => 3 } );
+    ok( $patrons->is_paged, 'Search is paged' );
+
+    $schema->storage->txn_rollback;
+}