Bug 17594: Make Koha::Object->discard_changes available
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 9 Nov 2016 13:20:16 +0000 (13:20 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Tue, 15 Nov 2016 15:15:26 +0000 (15:15 +0000)
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>
Koha/Object.pm
t/db_dependent/Koha/Object.t

index b5e11af..a9e35ba 100644 (file)
@@ -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;
 
index 4b0a1c4..9ea5e8c 100755 (executable)
 
 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;