From c89486ddab38cc1446d4879a2cf70840604f574e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 26 Jan 2017 12:26:17 +0100 Subject: [PATCH] Bug 18003: Example of why we would need a PK on deletedborrowers These tests do not pass: DBIx::Class::ResultSource::_pri_cols_or_die(): Operation requires a primary key to be declared on 'Deletedborrower' via set_primary_key at t/db_dependent/Koha/Patrons.t line 329 --- t/db_dependent/Koha/Patrons.t | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 0e6791a..ad668bc 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -318,20 +318,22 @@ subtest 'renew_account' => sub { }; subtest "move_to_deleted" => sub { - plan tests => 5; + plan tests => 6; my $originally_updated_on = '2016-01-01 12:12:12'; my $patron = $builder->build( { source => 'Borrower',value => { updated_on => $originally_updated_on } } ); my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); - is( ref( $retrieved_patron->move_to_deleted ), 'Koha::Schema::Result::Deletedborrower', 'Koha::Patron->move_to_deleted should return the Deleted patron' ) + my $deleted_patron = $retrieved_patron->move_to_deleted; + is( ref( $deleted_patron ), 'Koha::Schema::Result::Deletedborrower', 'Koha::Patron->move_to_deleted should return the Deleted patron' ) ; # FIXME This should be Koha::Deleted::Patron - my $deleted_patron = $schema->resultset('Deletedborrower') - ->search( { borrowernumber => $patron->{borrowernumber} }, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } ) - ->next; + + $deleted_patron->discard_changes; + ok( $retrieved_patron->updated_on, 'updated_on should be set for borrowers table' ); - ok( $deleted_patron->{updated_on}, 'updated_on should be set for deleted_borrowers table' ); - isnt( $deleted_patron->{updated_on}, $retrieved_patron->updated_on, 'Koha::Patron->move_to_deleted should have correctly updated the updated_on column'); - $deleted_patron->{updated_on} = $originally_updated_on; #reset for simplicity in comparing all other fields - is_deeply( $deleted_patron, $patron, 'Koha::Patron->move_to_deleted should have correctly moved the patron to the deleted table' ); + ok( $deleted_patron->updated_on, 'updated_on should be set for deleted_borrowers table' ); + is( dt_from_string($deleted_patron->updated_on)->truncate( to => 'day' ), dt_from_string->truncate( to => 'day' ), 'The updated_on value for the deleted patron should be today' ); + isnt( $deleted_patron->updated_on, $retrieved_patron->updated_on, 'Koha::Patron->move_to_deleted should have correctly updated the updated_on column'); + $deleted_patron->updated_on($originally_updated_on); #reset for simplicity in comparing all other fields + is_deeply( { $deleted_patron->get_columns }, $patron, 'Koha::Patron->move_to_deleted should have correctly moved the patron to the deleted table' ); $retrieved_patron->delete( $patron->{borrowernumber} ); # Cleanup }; -- 2.1.4