Bugzilla – Attachment 60697 Details for
Bug 18174
Add the Koha::Object->update method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18174: Add update to Koha::Object
Bug-18174-Add-update-to-KohaObject.patch (text/plain), 3.11 KB, created by
Marcel de Rooy
on 2017-02-27 09:58:43 UTC
(
hide
)
Description:
Bug 18174: Add update to Koha::Object
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2017-02-27 09:58:43 UTC
Size:
3.11 KB
patch
obsolete
>From b4d2619575571848c94cc8c2f1690d05ebea0a82 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 27 Feb 2017 10:57:18 +0100 >Subject: [PATCH] Bug 18174: Add update to Koha::Object >Content-Type: text/plain; charset=utf-8 > >Still work in progress >--- > Koha/Object.pm | 8 ++++++-- > t/db_dependent/Koha/Object.t | 28 ++++++++++++++++++++++++++-- > 2 files changed, 32 insertions(+), 4 deletions(-) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index 22e11b6..d5e5df5 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -301,13 +301,17 @@ sub AUTOLOAD { > } > } > >- my @known_methods = qw( is_changed id in_storage get_column discard_changes); >+ my @known_methods = qw( is_changed id in_storage get_column discard_changes update ); > > Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods; > >+ if( !$self->_result->can($method) ) { >+ Koha::Exceptions::Object::MethodNotFound->throw( "No method $method for " . ref($self) ); >+ } >+ > my $r = eval { $self->_result->$method(@_) }; > if ( $@ ) { >- Koha::Exceptions::Object::MethodNotFound->throw( "No method $method for " . ref($self) ); >+ Koha::Exceptions::Object->throw( ref($self) . "::$method generated this error: " . $@ ); > } > return $r; > } >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index d812d37..c489101 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -17,14 +17,16 @@ > > use Modern::Perl; > >-use Test::More tests => 8; >+use Test::More tests => 9; > use Test::Warn; > > use C4::Context; > use Koha::Database; > use Koha::DateUtils qw( dt_from_string ); >+use Koha::Libraries; > > use Scalar::Util qw( isvstring ); >+use Try::Tiny; > > use t::lib::TestBuilder; > >@@ -168,6 +170,28 @@ subtest 'TO_JSON tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest "Test update method" => sub { >+ plan tests => 6; > >+ $schema->storage->txn_begin; >+ my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; >+ my $library = Koha::Libraries->find( $branchcode ); >+ $library->update({ branchname => 'New_Name', branchcity => 'AMS' }); >+ is( $library->branchname, 'New_Name', 'Changed name with update' ); >+ is( $library->branchcity, 'AMS', 'Changed city too' ); >+ is( $library->is_changed, 0, 'Change should be stored already' ); >+ try { >+ $library->update({ >+ branchcity => 'NYC', not_a_column => 53, branchname => 'Name3', >+ }); >+ ok( 0, 'It should not be possible to update an unexisting column without an error from Koha::Object/DBIx' ); >+ } catch { >+ ok( $_->isa('Koha::Exceptions::Object'), 'Caught error when updating wrong column' ); >+ }; >+ # DBIx behavior is not reliable; run the test multiple times >+ # The test mostly fails on one or both, but sometimes passes >+ is( $library->branchcity, 'NYC', 'DBIx updated the first column' ); >+ is( $library->branchname, 'New_Name', 'DBIx did not update the third column' ); > >-1; >+ $schema->storage->txn_rollback; >+}; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18174
:
60697
|
60698
|
60699
|
60721
|
60889