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>
This commit is contained in:
parent
4277f43a91
commit
1da4a7b4a2
2 changed files with 20 additions and 2 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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…
Reference in a new issue