Bug 18930: (RM follow-up) Restore primary key find
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 12 Jul 2019 13:55:09 +0000 (14:55 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 16 Jul 2019 12:53:54 +0000 (13:53 +0100)
The find method in RefundLostItemFeeRules had been overloaded to only
support a hash being passed, however find can be called with a bare
array of primary key values (i.e. id in this case).  TestBuilder relies
on this functionality and started to fail; This patch simply restores
the original behaviour for when a single value (or array of values) is
passed.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/RefundLostItemFeeRules.pm
Koha/Schema/Result/CirculationRule.pm
t/db_dependent/RefundLostItemFeeRule.t
t/lib/TestBuilder.pm

index 9112e08..86b01f0 100644 (file)
@@ -36,7 +36,7 @@ Koha::RefundLostItemFeeRules - Koha RefundLostItemFeeRules object set class
 
 =cut
 
-=head3 type
+=head3 _type
 
 =cut
 
@@ -145,7 +145,9 @@ Inherit from Koha::Objects->find(), but forces rule_name => 'refund'
 sub find {
     my ( $self, @pars ) = @_;
 
-    $pars[0]->{rule_name} = 'refund';
+    if ( ref($pars[0]) eq 'HASH' ) {
+        $pars[0]->{rule_name} = 'refund';
+    }
 
     return $self->SUPER::find(@pars);
 }
index 7b26b37..80e6cc2 100644 (file)
@@ -180,6 +180,13 @@ __PACKAGE__->belongs_to(
 # Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-05 14:29:17
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QHMqvrtX0ohJe70PHUYZ0Q
 
+sub koha_objects_class {
+    'Koha::CirculationRules';
+}
+
+sub koha_object_class {
+    'Koha::CirculationRule';
+}
 
 # You can replace this text with custom code or comments, and it will be preserved on regeneration
 1;
index 2dd15fd..4599165 100755 (executable)
@@ -374,7 +374,7 @@ subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub {
 
 subtest 'Koha::RefundLostItemFeeRules::find() tests' => sub {
 
-    plan tests => 4;
+    plan tests => 5;
 
     # Start transaction
     $schema->storage->txn_begin;
@@ -395,6 +395,9 @@ subtest 'Koha::RefundLostItemFeeRules::find() tests' => sub {
             }
         }
     );
+
+    ok(defined Koha::RefundLostItemFeeRules->find($default_non_refund->{id}), 'Find should continue to work when passed an id');
+
     my $specific_non_refund = $builder->build(
         {
             source => 'CirculationRule',
index 3bfcb86..87caf63 100644 (file)
@@ -565,6 +565,9 @@ sub _gen_default_values {
         AuthHeader => {
             marcxml => '',
         },
+        RefundLostItemFeeRules => {
+            rule_name => 'refund',
+        },
     };
 }