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

(-)a/Koha/Object.pm (-2 / +11 lines)
Lines 57-64 sub new { Link Here
57
    my $self = {};
57
    my $self = {};
58
58
59
    if ($attributes) {
59
    if ($attributes) {
60
        $self->{_result} =
60
        my $schema = Koha::Database->new->schema;
61
          Koha::Database->new()->schema()->resultset( $class->_type() )
61
62
        # Remove the arguments which exist, are not defined but NOT NULL to use the default value
63
        my $columns_info = $schema->resultset( $class->_type )->result_source->columns_info;
64
        for my $column_name ( keys %$attributes ) {
65
            my $c_info = $columns_info->{$column_name};
66
            next if $c_info->{is_nullable};
67
            next if not exists $attributes->{$column_name} or defined $attributes->{$column_name};
68
            delete $attributes->{$column_name};
69
        }
70
        $self->{_result} = $schema->resultset( $class->_type() )
62
          ->new($attributes);
71
          ->new($attributes);
63
    }
72
    }
64
73
(-)a/t/db_dependent/Koha/Objects.t (-2 / +14 lines)
Lines 19-29 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 7;
22
use Test::More tests => 8;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use Koha::Authority::Types;
25
use Koha::Authority::Types;
26
use Koha::Cities;
26
use Koha::Cities;
27
use Koha::Patron::Category;
28
use Koha::Patron::Categories;
27
use Koha::Patrons;
29
use Koha::Patrons;
28
use Koha::Database;
30
use Koha::Database;
29
31
Lines 80-85 subtest 'not_covered_yet' => sub { Link Here
80
    plan tests => 1;
82
    plan tests => 1;
81
    warning_is { Koha::Patrons->search->not_covered_yet } { carped => 'The method not_covered_yet is not covered by tests' }, "If a method is not covered by tests, the AUTOLOAD method won't execute the method";
83
    warning_is { Koha::Patrons->search->not_covered_yet } { carped => 'The method not_covered_yet is not covered by tests' }, "If a method is not covered by tests, the AUTOLOAD method won't execute the method";
82
};
84
};
85
subtest 'new' => sub {
86
    plan tests => 2;
87
    my $a_cat_code = 'A_CAT_CODE';
88
    my $patron_category = Koha::Patron::Category->new( { categorycode => $a_cat_code } )->store;
89
    is( Koha::Patron::Categories->find($a_cat_code)->category_type, 'A', 'Koha::Object->new should set the default value' );
90
    Koha::Patron::Categories->find($a_cat_code)->delete;
91
    $patron_category = Koha::Patron::Category->new( { categorycode => $a_cat_code, category_type => undef } )->store;
92
    is( Koha::Patron::Categories->find($a_cat_code)->category_type, 'A', 'Koha::Object->new should set the default value even if the argument exists but is not defined' );
93
    Koha::Patron::Categories->find($a_cat_code)->delete;
94
};
83
95
84
$schema->storage->txn_rollback;
96
$schema->storage->txn_rollback;
85
1;
97
1;
86
- 
98

Return to bug 17080