Bug 15656 [QA Followup] - Return without searching if patron has no guarantor
authorKyle M Hall <kyle@bywatersolutions.com>
Fri, 11 Mar 2016 18:35:47 +0000 (18:35 +0000)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Sat, 12 Mar 2016 23:40:10 +0000 (23:40 +0000)
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com

Koha/Patron.pm
t/db_dependent/Koha/Patrons.t

index 4464731..684f274 100644 (file)
@@ -45,6 +45,8 @@ Returns a Koha::Patron object for this patron's guarantor
 sub guarantor {
     my ( $self ) = @_;
 
+    return undef unless $self->guarantorid();
+
     return Koha::Patrons->find( $self->guarantorid() );
 }
 
@@ -76,13 +78,14 @@ sub siblings {
     my ( $self ) = @_;
 
     my $guarantor = $self->guarantor;
-    my $guarantorid = $guarantor ? $guarantor->borrowernumber : undef;
+
+    return undef unless $guarantor;
 
     return Koha::Patrons->search(
         {
             guarantorid => {
                 '!=' => undef,
-                '=' => $guarantorid,
+                '=' => $guarantor->id,
             },
             borrowernumber => {
                 '!=' => $self->borrowernumber,
index 46eed31..fafd829 100644 (file)
@@ -80,7 +80,7 @@ subtest 'guarantees' => sub {
 subtest 'siblings' => sub {
     plan tests => 7;
     my $siblings = $new_patron_1->siblings;
-    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should not crashed if the patron has not guarantor' );
+    is( $siblings, undef, 'Koha::Patron->siblings should not crashed if the patron has no guarantor' );
     my $guarantee_1 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
     my $retrieved_guarantee_1 = Koha::Patrons->find($guarantee_1);
     $siblings = $retrieved_guarantee_1->siblings;