From 4962304a487e2bafd0d830475adc7870afcfa42f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 28 Mar 2025 16:58:32 +1100 Subject: [PATCH] Deal with nil values in sum Rails was doing that for us but Rails 7.1 won't. --- config/environments/test.rb | 1 - lib/reporting/reports/bulk_coop/customer_payments.rb | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index e241e5c4ce..2e14aea9c3 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -58,7 +58,6 @@ Openfoodnetwork::Application.configure do ActiveSupport::Deprecation.behavior = ->(message, callstack, deprecation_horizon, gem_name) do allowed_warnings = [ # List strings here to allow matching deprecations. - "Enumerable.sum", # spec/lib/reports/bulk_coop_report_spec.rb:188 ] unless allowed_warnings.any? { |pattern| message.match(pattern) } ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:raise].call(message, callstack, deprecation_horizon, gem_name) diff --git a/lib/reporting/reports/bulk_coop/customer_payments.rb b/lib/reporting/reports/bulk_coop/customer_payments.rb index 97752b3feb..4e4da4ce12 100644 --- a/lib/reporting/reports/bulk_coop/customer_payments.rb +++ b/lib/reporting/reports/bulk_coop/customer_payments.rb @@ -21,15 +21,15 @@ module Reporting private def customer_payments_total_cost(line_items) - unique_orders(line_items).sum(&:total) + unique_orders(line_items).map(&:total).sum(&:to_f) end def customer_payments_amount_owed(line_items) - unique_orders(line_items).sum(&:new_outstanding_balance) + unique_orders(line_items).map(&:new_outstanding_balance).sum(&:to_f) end def customer_payments_amount_paid(line_items) - unique_orders(line_items).sum(&:payment_total) + unique_orders(line_items).map(&:payment_total).sum(&:to_f) end def unique_orders(line_items)