From 8dfbc46aa4bebffb5e7bd262612ef9d08d24e5d3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 2 Jun 2020 14:40:04 +0200 Subject: [PATCH] Bug 25638: Fix float/decimal comparison in API related tests The previous fix from bug 25513 does not work in all versions we are supporting. Let's hack the float/decimal columns in the same way we did for integer. prove t/db_dependent/api/v1/acquisitions_vendors.t \ t/db_dependent/api/v1/patrons_accounts.t \ t/db_dependent/api/v1/acquisitions_orders.t Note that there is another error on U20 for acquisitions_orders.t Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- Koha/Object.pm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index ed7cc4bdc9..6a741400be 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -362,6 +362,15 @@ sub TO_JSON { # is ported to whatever distro we support by that time $unblessed->{$col} += 0; } + elsif ( _decimal_column_type( $columns_info->{$col}->{data_type} ) + and looks_like_number( $unblessed->{$col} ) + ) { + + # TODO: Remove once the solution for + # https://rt.cpan.org/Ticket/Display.html?id=119904 + # is ported to whatever distro we support by that time + $unblessed->{$col} += 0.00; + } elsif ( _datetime_column_type( $columns_info->{$col}->{data_type} ) ) { eval { return unless $unblessed->{$col}; @@ -410,12 +419,24 @@ sub _numeric_column_type { 'mediumint', 'smallint', 'tinyint', + ); + + return ( grep { $column_type eq $_ } @numeric_types) ? 1 : 0; +} + +sub _decimal_column_type { + # TODO: Remove once the solution for + # https://rt.cpan.org/Ticket/Display.html?id=119904 + # is ported to whatever distro we support by that time + my ($column_type) = @_; + + my @decimal_types = ( 'decimal', 'double precision', 'float' ); - return ( grep { $column_type eq $_ } @numeric_types) ? 1 : 0; + return ( grep { $column_type eq $_ } @decimal_types) ? 1 : 0; } =head3 prefetch_whitelist -- 2.39.5