View | Details | Raw Unified | Return to bug 18174
Collapse All | Expand All

(-)a/Koha/Object.pm (-2 / +6 lines)
Lines 301-313 sub AUTOLOAD { Link Here
301
        }
301
        }
302
    }
302
    }
303
303
304
    my @known_methods = qw( is_changed id in_storage get_column discard_changes);
304
    my @known_methods = qw( is_changed id in_storage get_column discard_changes update );
305
305
306
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods;
306
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods;
307
307
308
    if( !$self->_result->can($method) ) {
309
        Koha::Exceptions::Object::MethodNotFound->throw( "No method $method for " . ref($self) );
310
    }
311
308
    my $r = eval { $self->_result->$method(@_) };
312
    my $r = eval { $self->_result->$method(@_) };
309
    if ( $@ ) {
313
    if ( $@ ) {
310
        Koha::Exceptions::Object::MethodNotFound->throw( "No method $method for " . ref($self) );
314
        Koha::Exceptions::Object->throw( ref($self) . "::$method generated this error: " . $@ );
311
    }
315
    }
312
    return $r;
316
    return $r;
313
}
317
}
(-)a/t/db_dependent/Koha/Object.t (-3 / +26 lines)
Lines 17-30 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 8;
20
use Test::More tests => 9;
21
use Test::Warn;
21
use Test::Warn;
22
22
23
use C4::Context;
23
use C4::Context;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
26
use Koha::Libraries;
26
27
27
use Scalar::Util qw( isvstring );
28
use Scalar::Util qw( isvstring );
29
use Try::Tiny;
28
30
29
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
30
32
Lines 168-173 subtest 'TO_JSON tests' => sub { Link Here
168
    $schema->storage->txn_rollback;
170
    $schema->storage->txn_rollback;
169
};
171
};
170
172
173
subtest "Test update method" => sub {
174
    plan tests => 6;
171
175
176
    $schema->storage->txn_begin;
177
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
178
    my $library = Koha::Libraries->find( $branchcode );
179
    $library->update({ branchname => 'New_Name', branchcity => 'AMS' });
180
    is( $library->branchname, 'New_Name', 'Changed name with update' );
181
    is( $library->branchcity, 'AMS', 'Changed city too' );
182
    is( $library->is_changed, 0, 'Change should be stored already' );
183
    try {
184
        $library->update({
185
            branchcity => 'NYC', not_a_column => 53, branchname => 'Name3',
186
        });
187
        ok( 0, 'It should not be possible to update an unexisting column without an error from Koha::Object/DBIx' );
188
    } catch {
189
        ok( $_->isa('Koha::Exceptions::Object'), 'Caught error when updating wrong column' );
190
    };
191
    # DBIx behavior is not reliable; run the test multiple times
192
    # The test mostly fails on one or both, but sometimes passes
193
    is( $library->branchcity, 'NYC', 'DBIx updated the first column' );
194
    is( $library->branchname, 'New_Name', 'DBIx did not update the third column' );
172
195
173
1;
196
    $schema->storage->txn_rollback;
197
};
174
- 

Return to bug 18174