From a96c944c17c6fbeb399077732ab81664e469cb08 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 Signed-off-by: Kyle M Hall --- 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 34ce896154..39edcc743a 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