Bugzilla – Attachment 97391 Details for
Bug 23893
Add ->new_from_api and ->set_from_api methods to Koha::Object
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23893: Special care for booleans
Bug-23893-Special-care-for-booleans.patch (text/plain), 2.92 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-01-15 12:55:37 UTC
(
hide
)
Description:
Bug 23893: Special care for booleans
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-01-15 12:55:37 UTC
Size:
2.92 KB
patch
obsolete
>From ef1725862c82e52ea9fdc9470ebc4cb1f0bcfaf8 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 15 Jan 2020 09:45:24 -0300 >Subject: [PATCH] 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> >--- > Koha/Object.pm | 7 ++++++- > t/db_dependent/Koha/Object.t | 19 +++++++++++++++---- > 2 files changed, 21 insertions(+), 5 deletions(-) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index 4725f2362f..5f28c35808 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -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'); > } >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index bd466b984c..bcee55ca75 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -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 { >-- >2.25.0
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 23893
:
95276
|
95277
|
95278
|
95311
|
95312
|
95313
|
95314
|
95315
|
96126
|
96127
|
96128
|
96129
|
96130
|
96652
|
96655
|
96656
|
96657
|
96658
|
96659
|
96660
|
96661
|
96662
|
96665
|
96666
|
96920
|
96921
|
96922
|
96923
|
96924
|
96925
|
96926
|
96927
|
96928
|
96929
|
96930
|
96931
|
96932
|
96933
|
96934
|
96935
|
96936
|
96937
| 97391