Bug 23893: Special care for booleans
This patch acknowledges the fact that in D8 the Mojo::JSON->true and Mojo::JSON->false values don't translate into integers when passed to DBIC. It works correctly on D9 onwards, but we haven't formally deprecated Jessie. This is adding back this translation, in the right place now that all mappings code has been integrated into Koha::Object(s) directly. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
feb625ce50
commit
8b130c2eed
2 changed files with 21 additions and 5 deletions
|
@ -545,7 +545,12 @@ sub attributes_from_api {
|
|||
? $from_api_mapping->{$key}
|
||||
: $key;
|
||||
|
||||
if ( _date_or_datetime_column_type( $columns_info->{$koha_field_name}->{data_type} ) ) {
|
||||
if ( $columns_info->{$koha_field_name}->{is_boolean} ) {
|
||||
# TODO: Remove when D8 is formally deprecated
|
||||
# Handle booleans gracefully
|
||||
$value = ( $value ) ? 1 : 0;
|
||||
}
|
||||
elsif ( _date_or_datetime_column_type( $columns_info->{$koha_field_name}->{data_type} ) ) {
|
||||
try {
|
||||
$value = dt_from_string($value, 'rfc3339');
|
||||
}
|
||||
|
|
|
@ -455,15 +455,13 @@ subtest 'new_from_api() tests' => sub {
|
|||
|
||||
subtest 'attributes_from_api() tests' => sub {
|
||||
|
||||
plan tests => 8;
|
||||
plan tests => 12;
|
||||
|
||||
my $patron = Koha::Patron->new();
|
||||
|
||||
use Data::Printer colored => 1;
|
||||
|
||||
my $attrs = $patron->attributes_from_api(
|
||||
{
|
||||
updated_on => '2019-12-27T14:53:00'
|
||||
updated_on => '2019-12-27T14:53:00',
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -519,6 +517,19 @@ subtest 'attributes_from_api() tests' => sub {
|
|||
'date_of_birth',
|
||||
'Exception parameter is the API field name, not the DB one'
|
||||
);
|
||||
|
||||
# Booleans
|
||||
$attrs = $patron->attributes_from_api(
|
||||
{
|
||||
incorrect_address => Mojo::JSON->true,
|
||||
patron_card_lost => Mojo::JSON->false,
|
||||
}
|
||||
);
|
||||
|
||||
ok( exists $attrs->{gonenoaddress}, 'Attribute gets translated' );
|
||||
is( $attrs->{gonenoaddress}, 1, 'Boolean correctly translated to integer (true => 1)' );
|
||||
ok( exists $attrs->{lost}, 'Attribute gets translated' );
|
||||
is( $attrs->{lost}, 0, 'Boolean correctly translated to integer (false => 0)' );
|
||||
};
|
||||
|
||||
subtest "Test update method" => sub {
|
||||
|
|
Loading…
Reference in a new issue