From b1b9e0ddfd98d144c778a4f5e23e0dc3e9bd7aa4 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 --- 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 34ce8961544..39edcc743ac 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 d258e70c13a..73007c18a08 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.25.1