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

(-)a/Koha/Object.pm (-3 / +2 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
306
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods;
305
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods;
307
306
308
    my $r = eval { $self->_result->$method(@_) };
307
    my $r = eval { $self->_result->$method(@_) };
309
    if ( $@ ) {
308
    if ( $@ ) {
310
        Koha::Exceptions::Object::MethodNotFound->throw( "No method $method for " . ref($self) );
309
        Koha::Exceptions::Object->throw( ref($self) . "::$method generated this error: " . $@ );
311
    }
310
    }
312
    return $r;
311
    return $r;
313
}
312
}
(-)a/t/db_dependent/Koha/Object.t (-3 / +27 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;
175
176
    $schema->storage->txn_begin;
171
177
178
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
179
    my $library = Koha::Libraries->find( $branchcode );
180
    $library->update({ branchname => 'New_Name', branchcity => 'AMS' });
181
    is( $library->branchname, 'New_Name', 'Changed name with update' );
182
    is( $library->branchcity, 'AMS', 'Changed city too' );
183
    is( $library->is_changed, 0, 'Change should be stored already' );
184
    try {
185
        $library->update({
186
            branchcity => 'NYC', not_a_column => 53, branchname => 'Name3',
187
        });
188
        fail( 'It should not be possible to update an unexisting column without an error from Koha::Object/DBIx' );
189
    } catch {
190
        ok( $_->isa('Koha::Exceptions::Object'), 'Caught error when updating wrong column' );
191
        $library->discard_changes; #requery after failing update
192
    };
193
    # Check if the columns are not updated
194
    is( $library->branchcity, 'AMS', 'First column not updated' );
195
    is( $library->branchname, 'New_Name', 'Third column not updated' );
172
196
173
1;
197
    $schema->storage->txn_rollback;
198
};
174
- 

Return to bug 18174