Browse Source

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 <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
16.11.x
Jonathan Druart 8 years ago
committed by Kyle M Hall
parent
commit
1da4a7b4a2
  1. 2
      Koha/Object.pm
  2. 20
      t/db_dependent/Koha/Object.t

2
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;

20
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;

Loading…
Cancel
Save