diff --git a/config/environments/test.rb b/config/environments/test.rb index cfba7d0307..2e14aea9c3 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -52,7 +52,17 @@ Openfoodnetwork::Application.configure do # config.active_record.schema_format = :sql # Print deprecation notices to the stderr - config.active_support.deprecation = :stderr + # config.active_support.deprecation = :stderr + + # Fail tests on deprecated code unless it's a known case to solve. + ActiveSupport::Deprecation.behavior = ->(message, callstack, deprecation_horizon, gem_name) do + allowed_warnings = [ + # List strings here to allow matching deprecations. + ] + unless allowed_warnings.any? { |pattern| message.match(pattern) } + ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:raise].call(message, callstack, deprecation_horizon, gem_name) + end + end config.active_job.queue_adapter = :test end diff --git a/config/initializers/deprecations.rb b/config/initializers/deprecations.rb new file mode 100644 index 0000000000..76d05f9acd --- /dev/null +++ b/config/initializers/deprecations.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +ActiveSupport::Notifications.subscribe(/deprecation/) do |_name, _start, _finish, _id, payload| + e = ActiveSupport::DeprecationException.new(payload[:message]) + e.set_backtrace(payload[:callstack].map(&:to_s)) + + Bugsnag.notify(e) do |report| + report.severity = "warning" + report.add_tab( + :deprecation, + payload.except(:callstack), + ) + end +end 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)