From f5b62001228ba552f5be64a6ad9a2f6c806536ed Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 20 Jan 2022 11:20:49 +0100 Subject: [PATCH] Bug 21652: Simplify code And add a test. Signed-off-by: Jonathan Druart Signed-off-by: Fridolin Somers --- Koha/Hold.pm | 9 +-------- t/db_dependent/Hold.t | 12 ++++++------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 8a92099dee..67899b8c97 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -178,18 +178,11 @@ sub set_waiting { $self->priority(0); - my $waiting_date; my $today = dt_from_string(); - if ( $self->waitingdate ) { - $waiting_date = $self->waitingdate; - } else { - $waiting_date = $today->ymd; - } - my $values = { found => 'W', - waitingdate => $waiting_date, + ( !$self->waitingdate ? ( waitingdate => $today->ymd ) : () ), desk_id => $desk_id, }; diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t index d258e70c13..73007c18a0 100755 --- a/t/db_dependent/Hold.t +++ b/t/db_dependent/Hold.t @@ -227,21 +227,21 @@ subtest "store() tests" => sub { subtest "set_waiting() tests" => sub { - plan tests => 1; + plan tests => 2; $schema->storage->txn_begin(); - # Disable logging - t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); - my $hold = $builder->build_object({ class => 'Koha::Holds' }); $hold->waitingdate('2021-01-01'); - $hold->set_waiting(); + is($hold->waitingdate, '2021-01-01', "Setting waiting when already waiting should not update waitingdate"); - is($hold->waitingdate,'2021-01-01',"Setting waiting when already waiting should not update waitingdate"); + $hold->waitingdate(undef)->store; + $hold->set_waiting(); + isnt($hold->waitingdate, undef, "Setting waiting when not waiting already should update waitingdate"); + $schema->storage->txn_rollback(); }; subtest "delete() tests" => sub { -- 2.39.5