From 3107975ba95f5853ea1084afa01db598e4adeeea Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 10 Nov 2014 12:55:35 +0100 Subject: [PATCH] Bug 13019: (follow-up) Remove smartmatch operator This patch also adds 1 test. Signed-off-by: Jonathan Druart Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/Object.pm | 6 ++++-- Koha/Objects.pm | 12 ++++++------ t/db_dependent/Borrower.t | 14 +++++++++----- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index d1e0455915..0093ed1430 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -48,6 +48,8 @@ This class must always be subclassed. my $object = Koha::Object->new(); my $object = Koha::Object->new($attributes); +Note that this cannot be used to retrieve record from the DB. + =cut sub new { @@ -183,7 +185,7 @@ sub set { my @columns = @{$self->_columns()}; foreach my $p ( keys %$properties ) { - unless ( $p ~~ @columns ) { + unless ( grep {/^$p$/} @columns ) { carp("No property $p!"); return 0; } @@ -252,7 +254,7 @@ sub AUTOLOAD { my @columns = @{$self->_columns()}; # Using direct setter/getter like $item->barcode() or $item->barcode($barcode); - if ( $method ~~ @columns ) { + if ( grep {/^$method$/} @columns ) { if ( @_ ) { return $self->_result()->set_column( $method, @_ ); } else { diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 1eaf2be476..8c17665910 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -48,7 +48,7 @@ This class must be subclassed. =head3 Koha::Objects->new(); -my $object = Koha::Object->new(); +my $object = Koha::Objects->new(); =cut @@ -61,7 +61,7 @@ sub new { =head3 Koha::Objects->new_from_dbic(); -my $object = Koha::Object->new_from_dbic( $resultset ); +my $object = Koha::Objects->new_from_dbic( $resultset ); =cut @@ -74,8 +74,8 @@ sub new_from_dbic { =head3 Koha::Objects->find(); -my $object = Koha::Object->find($id); -my $object = Koha::Object->find( { keypart1 => $keypart1, keypart2 => $keypart2 } ); +my $object = Koha::Objects->find($id); +my $object = Koha::Objects->find( { keypart1 => $keypart1, keypart2 => $keypart2 } ); =cut @@ -91,7 +91,7 @@ sub find { =head3 Koha::Objects->search(); -my @objects = Koha::Object->search($params); +my @objects = Koha::Objects->search($params); =cut @@ -114,7 +114,7 @@ sub search { =head3 Koha::Objects->count(); -my @objects = Koha::Object->count($params); +my @objects = Koha::Objects->count($params); =cut diff --git a/t/db_dependent/Borrower.t b/t/db_dependent/Borrower.t index 620b6ff74d..8290cabbbf 100755 --- a/t/db_dependent/Borrower.t +++ b/t/db_dependent/Borrower.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 12; +use Test::More tests => 13; use Test::Warn; use C4::Context; @@ -45,12 +45,16 @@ $object->branchcode( $branchcode ); $object->surname("Test Surname"); $object->store(); -my $borrower = Koha::Database->new()->schema()->resultset('Borrower')->find( $object->borrowernumber() ); -is( $borrower->surname(), "Test Surname", "Object found in database" ); - is( $object->in_storage, 1, "Object is now stored" ); +my $borrowernumber = $object->borrowernumber; + +my $borrower = Koha::Database->new()->schema()->resultset('Borrower')->find( $borrowernumber ); +is( $borrower->surname(), "Test Surname", "Object found in database" ); + is( $object->is_changed(), 0, "Object is unchanged" ); +$object->surname("Test Surname"); +is( $object->is_changed(), 0, "Object is still unchanged" ); $object->surname("Test Surname 2"); is( $object->is_changed(), 1, "Object is changed" ); @@ -63,7 +67,7 @@ $object->store(); is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" ); $object->delete(); -$borrower = Koha::Database->new()->schema()->resultset('Borrower')->find( $object->borrowernumber() ); +$borrower = Koha::Database->new()->schema()->resultset('Borrower')->find( $borrowernumber ); ok( ! $borrower, "Object no longer found in database" ); is( $object->in_storage, 0, "Object is not in storage" ); -- 2.39.5