From 7758f1b8c8908d8691829886048abd1320fb065f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 17 Oct 2024 10:40:49 -0300 Subject: [PATCH] Bug 35717: (QA follow-up) ->suggestions() always returns a resultset This patch acknowledges the fact a one to many relationship always returns an iterator (even an empty one) so there's no point in having a codepath for it not returning a resultset. The tests are simplified for readability too. Signed-off-by: Tomas Cohen Arazi --- Koha/Acquisition/Order.pm | 6 ++--- t/db_dependent/Koha/Acquisition/Order.t | 32 ++++++++++++------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index 2d92e13dd7c..ebfc7a44d9d 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -309,10 +309,8 @@ to the order. =cut sub suggestions { - my ( $self ) = @_; - my $rs = $self->_result->suggestions; - return unless $rs; - return Koha::Suggestions->_new_from_dbic( $rs ); + my ($self) = @_; + return Koha::Suggestions->_new_from_dbic( scalar $self->_result->suggestions ); } =head3 current_item_level_holds diff --git a/t/db_dependent/Koha/Acquisition/Order.t b/t/db_dependent/Koha/Acquisition/Order.t index 3cc320fb034..7c86182c321 100755 --- a/t/db_dependent/Koha/Acquisition/Order.t +++ b/t/db_dependent/Koha/Acquisition/Order.t @@ -211,44 +211,42 @@ subtest 'subscription' => sub { }; subtest 'suggestions() tests' => sub { + plan tests => 4; $schema->storage->txn_begin; + my $o = $builder->build_object( { class => 'Koha::Acquisition::Orders', } ); - my $order = Koha::Acquisition::Orders->find( $o->ordernumber ); is( - ref( $order->suggestions ), 'Koha::Suggestions', + ref( $o->suggestions ), 'Koha::Suggestions', '->suggestions should return a Koha::Suggestions object' ); is( - $order->suggestions->count, 0, + $o->suggestions->count, 0, '->suggestions should return empty set if no linked suggestion' ); - $o = $builder->build_object( - { - class => 'Koha::Acquisition::Orders', - } - ); - $o = $builder->build_object( - { - class => 'Koha::Suggestions', - value => { ordernumber => $o->id } - } - ); + # Add a few suggestions + foreach ( 1..3 ) { + $builder->build_object( + { + class => 'Koha::Suggestions', + value => { ordernumber => $o->id } + } + ); + } - $order = Koha::Acquisition::Orders->find( $o->ordernumber ); is( - ref( $order->suggestions ), 'Koha::Suggestions', + ref( $o->suggestions ), 'Koha::Suggestions', '->suggestions should return a Koha::Suggestions object' ); is( - $order->suggestions->count, 1, + $o->suggestions->count, 3, '->suggestions should return linked suggestions' ); -- 2.47.0