From ce17dc90a196cc54803a6ca7fc94b0c1d31bc15a Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 12 Jul 2019 14:55:09 +0100 Subject: [PATCH] Bug 18930: (RM follow-up) Restore primary key find 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 --- Koha/RefundLostItemFeeRules.pm | 6 ++++-- Koha/Schema/Result/CirculationRule.pm | 7 +++++++ t/db_dependent/RefundLostItemFeeRule.t | 5 ++++- t/lib/TestBuilder.pm | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Koha/RefundLostItemFeeRules.pm b/Koha/RefundLostItemFeeRules.pm index 9112e08..86b01f0 100644 --- a/Koha/RefundLostItemFeeRules.pm +++ b/Koha/RefundLostItemFeeRules.pm @@ -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); } diff --git a/Koha/Schema/Result/CirculationRule.pm b/Koha/Schema/Result/CirculationRule.pm index 7b26b37..80e6cc2 100644 --- a/Koha/Schema/Result/CirculationRule.pm +++ b/Koha/Schema/Result/CirculationRule.pm @@ -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; diff --git a/t/db_dependent/RefundLostItemFeeRule.t b/t/db_dependent/RefundLostItemFeeRule.t index 2dd15fd..4599165 100755 --- a/t/db_dependent/RefundLostItemFeeRule.t +++ b/t/db_dependent/RefundLostItemFeeRule.t @@ -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', diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 3bfcb86..87caf63 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -565,6 +565,9 @@ sub _gen_default_values { AuthHeader => { marcxml => '', }, + RefundLostItemFeeRules => { + rule_name => 'refund', + }, }; } -- 1.7.2.5