Bugzilla – Attachment 173539 Details for
Bug 38273
Koha::Object->discard_changes should return the Koha::Object for chaining
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38273: Make sure same object is returned
Bug-38273-Make-sure-same-object-is-returned.patch (text/plain), 3.08 KB, created by
Kyle M Hall (khall)
on 2024-10-28 14:29:44 UTC
(
hide
)
Description:
Bug 38273: Make sure same object is returned
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2024-10-28 14:29:44 UTC
Size:
3.08 KB
patch
obsolete
>From cbdbe338b0664216a138827e9aea768fac1ce4f9 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 28 Oct 2024 09:13:29 -0300 >Subject: [PATCH] Bug 38273: Make sure same object is returned > >This patch adds a test to make sure the same object is returned. A code >change is also added to make sure the tests pass. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/Object.pm | 4 ++-- > t/db_dependent/Koha/Object.t | 32 +++++++++++++++----------------- > 2 files changed, 17 insertions(+), 19 deletions(-) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index 6b6faad84d8..0511d271573 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -226,8 +226,8 @@ Refetch the row from the DB > > sub discard_changes { > my ($self) = @_; >- my $object_class = Koha::Object::_get_object_class( $self->_result->result_class ); >- return $object_class->_new_from_dbic( $self->_result->discard_changes ); >+ $self->_result->discard_changes; >+ return $self; > } > > =head3 $object->update(); >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index 0cb41f19320..606182d2410 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -37,7 +37,7 @@ use Koha::Patrons; > use Koha::Library::Groups; > > use JSON; >-use Scalar::Util qw( isvstring ); >+use Scalar::Util qw( isvstring refaddr ); > use Try::Tiny; > > use t::lib::TestBuilder; >@@ -152,31 +152,29 @@ subtest 'get_column' => sub { > $schema->storage->txn_rollback; > }; > >-subtest 'discard_changes' => sub { >+subtest 'discard_changes() tests' => sub { >+ > plan tests => 3; > > $schema->storage->txn_begin; > >- my $patron = $builder->build( { source => 'Borrower' } ); >- $patron = Koha::Patrons->find( $patron->{borrowernumber} ); >+ my $date_expiry = dt_from_string->add( days => 30 ); >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { dateexpiry => $date_expiry } >+ } >+ ); > $patron->dateexpiry(dt_from_string); >- $patron->discard_changes; >+ my $ret = $patron->discard_changes; > is( > dt_from_string( $patron->dateexpiry ), >- dt_from_string->truncate( to => 'day' ), >+ $date_expiry->truncate( to => 'day' ), > 'discard_changes should refresh the object' > ); >- my $cardnumber = $patron->cardnumber; >- my $categorycode = $patron->categorycode; >- my $branchcode = $patron->branchcode; >- $patron->delete; >- >- $patron = >- Koha::Patron->new( { cardnumber => $cardnumber, categorycode => $categorycode, branchcode => $branchcode } ) >- ->store->discard_changes; >- >- is( ref($patron), 'Koha::Patron', 'discard_changes should return a Koha::Object object' ); >- isnt( $patron->updated_on, undef, 'discard_changes should have fetched the row from the DB' ); >+ is( ref($ret), 'Koha::Patron', 'discard_changes should return a Koha::Object object' ); >+ is( refaddr($ret), refaddr($patron), 'Same object referenced' ); > > $schema->storage->txn_rollback; > }; >-- >2.39.5 (Apple Git-154)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 38273
:
173507
|
173528
|
173529
|
173538
| 173539 |
173705