This patch also adds 1 test.
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
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 {
my @columns = @{$self->_columns()};
foreach my $p ( keys %$properties ) {
- unless ( $p ~~ @columns ) {
+ unless ( grep {/^$p$/} @columns ) {
carp("No property $p!");
return 0;
}
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 {
=head3 Koha::Objects->new();
-my $object = Koha::Object->new();
+my $object = Koha::Objects->new();
=cut
=head3 Koha::Objects->new_from_dbic();
-my $object = Koha::Object->new_from_dbic( $resultset );
+my $object = Koha::Objects->new_from_dbic( $resultset );
=cut
=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
=head3 Koha::Objects->search();
-my @objects = Koha::Object->search($params);
+my @objects = Koha::Objects->search($params);
=cut
=head3 Koha::Objects->count();
-my @objects = Koha::Object->count($params);
+my @objects = Koha::Objects->count($params);
=cut
use Modern::Perl;
-use Test::More tests => 12;
+use Test::More tests => 13;
use Test::Warn;
use C4::Context;
$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" );
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" );