From 1da4a7b4a204033b21e8537b2988bdd43a7357ec Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Nov 2016 13:20:16 +0000 Subject: [PATCH] Bug 17594: Make Koha::Object->discard_changes available We need this new method to refresh an object after it has been updated. Test plan: prove t/db_dependent/Koha/Object.t should return green Signed-off-by: Josef Moravec Signed-off-by: Kyle M Hall --- Koha/Object.pm | 2 +- t/db_dependent/Koha/Object.t | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index b5e11af2d7..a9e35ba6f7 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -246,7 +246,7 @@ sub AUTOLOAD { } } - my @known_methods = qw( is_changed id in_storage get_column ); + my @known_methods = qw( is_changed id in_storage get_column discard_changes); Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods; diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index 4b0a1c4513..9ea5e8cab7 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -17,11 +17,14 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; use Test::Warn; use C4::Context; use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); + +use t::lib::TestBuilder; BEGIN { use_ok('Koha::Object'); @@ -89,4 +92,19 @@ subtest 'get_column' => sub { my $patron = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode })->store; is( $patron->get_column('borrowernumber'), $patron->borrowernumber, 'get_column should retrieve the correct value' ); }; + +subtest 'discard_changes' => sub { + plan tests => 1; + my $builder = t::lib::TestBuilder->new; + my $patron = $builder->build( { source => 'Borrower' } ); + $patron = Koha::Patrons->find( $patron->{borrowernumber} ); + $patron->dateexpiry(dt_from_string); + $patron->discard_changes; + is( + dt_from_string( $patron->dateexpiry ), + dt_from_string->truncate( to => 'day' ), + 'discard_changes should refresh the object' + ); +}; + 1; -- 2.39.5