From 276b64692520108431c539b4d9124b3371129419 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 7 Jan 2020 13:30:32 +0100 Subject: [PATCH] Bug 21684: Koha::Object->delete must return a Koha::Object Not a DBIx::Class object. Tests have been added, add Bookseller.t fixed Signed-off-by: Martin Renvoize --- Koha/Object.pm | 7 ++++++- t/db_dependent/Bookseller.t | 2 +- t/db_dependent/Koha/Objects.t | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index 2139e070b3..589ea8c5d8 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -216,7 +216,12 @@ Returns: sub delete { my ($self) = @_; - return $self->_result()->delete; + my $deleted = $self->_result()->delete; + if ( ref $deleted ) { + my $object_class = Koha::Object::_get_object_class( $self->_result->result_class ); + $deleted = $object_class->_new_from_dbic($deleted); + } + return $deleted; } =head3 $object->set( $properties_hashref ) diff --git a/t/db_dependent/Bookseller.t b/t/db_dependent/Bookseller.t index c6f4c7fa24..ace46b86ed 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -105,7 +105,7 @@ is( Koha::Acquisition::Booksellers->search()->count, #Test DelBookseller my $del = $supplier1->delete; -is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " ); +is( ref($del), 'Koha::Acquisition::Bookseller', "DelBookseller returns the supplier object - supplier has been deleted " ); my $b = Koha::Acquisition::Booksellers->find( $id_supplier1 ); is( $b, undef, "Supplier1 has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" ); diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t index 43810fde02..f6a3ecd4e9 100644 --- a/t/db_dependent/Koha/Objects.t +++ b/t/db_dependent/Koha/Objects.t @@ -345,7 +345,7 @@ subtest 'Return same values as DBIx::Class' => sub { subtest 'Koha::Object->delete' => sub { - plan tests => 4; + plan tests => 5; my ( $r_us, $e_us, $r_them, $e_them ); @@ -358,6 +358,7 @@ subtest 'Return same values as DBIx::Class' => sub { 'Successful delete should return the object ' ); ok( !defined $e_us && !defined $e_them, 'Successful delete should not raise an exception' ); + is( ref($r_us), 'Koha::City', 'Successful delete should return our Koha::Obect based object' ); # CASE 2 - Delete an object that is not in storage try { $r_us = $r_us->delete; } catch { $e_us = $_ }; @@ -463,7 +464,7 @@ subtest 'Return same values as DBIx::Class' => sub { subtest 'Koha::Object->delete' => sub { - plan tests => 6; + plan tests => 7; my ( $r_us, $e_us, $r_them, $e_them ); @@ -480,6 +481,8 @@ subtest 'Return same values as DBIx::Class' => sub { 'Successful delete should return the patron object' ); ok( !defined $e_us && !defined $e_them, 'Successful delete should not raise an exception' ); + is( ref($r_us), 'Koha::Patron', + 'Successful delete should return our Koha::Obect based object' ); # CASE 2 - Delete a patron that is not in storage try { $r_us = $r_us->delete; } catch { $e_us = $_ }; -- 2.39.5