From db513470e08446cd8b3a3dcad21eccdddf15dc17 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 28 Mar 2025 14:59:32 +1100 Subject: [PATCH 1/3] Fail CI on unknown deprecation warnings --- config/environments/test.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index cfba7d0307..e241e5c4ce 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -52,7 +52,18 @@ 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. + "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) + end + end config.active_job.queue_adapter = :test end From 007154ef2885647e29e71eb6bef060219cb03c30 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 28 Mar 2025 15:49:34 +1100 Subject: [PATCH 2/3] Notify Bugsnag on deprecations in staging & production The behaviour was set to `notify` already but we were missing a notification handler. Now we'll get alerted about deprecations which were not covered by specs. --- config/initializers/deprecations.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 config/initializers/deprecations.rb 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 From 4962304a487e2bafd0d830475adc7870afcfa42f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 28 Mar 2025 16:58:32 +1100 Subject: [PATCH 3/3] 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)