From 8818a98230723c872a2036d81136a9bf88c5f075 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 29 Oct 2025 13:10:42 +0000 Subject: [PATCH 1/3] Catches exceptions on final_weight_volume inputs --- .../order_cycle_customer_totals_report_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb index ac9179c2ce..a7c308740d 100644 --- a/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb @@ -77,6 +77,24 @@ RSpec.describe Reporting::Reports::OrdersAndFulfillment::OrderCycleCustomerTotal expect(report.rows.first.shipment_state).to eq order.shipment_state end end + + describe "final weight volume column" do + # related to https://github.com/openfoodfoundation/openfoodnetwork/issues/13270 + # not sure how we got DEPRECATION WARNING: Rails 7.0 has deprecated Enumerable.sum + # but these scenarios might be related + it "handles a nil instead of an actual value" do + order.line_items[0].update!(final_weight_volume: nil) + expect { report_table }.to raise_error(TypeError, "nil can't be coerced into Integer") + end + it "it handles a missing value" do + order.line_items[0].update!(final_weight_volume: "") + expect { report_table }.to raise_error(TypeError, "nil can't be coerced into Integer") + end + it "handles a string input" do + order.line_items[0].update!(final_weight_volume: "a string") + expect { report_table }.not_to raise_error + end + end end context "loading shipping methods" do From 04fc729a5af3c6593e670c5a1a949410388aed1f Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 31 Oct 2025 16:45:14 +0000 Subject: [PATCH 2/3] Changes tests not to trigger error after https://github.com/openfoodfoundation/openfoodnetwork/pull/13571 was merged --- .../order_cycle_customer_totals_report_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb index a7c308740d..97a4fd26b9 100644 --- a/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb @@ -84,12 +84,14 @@ RSpec.describe Reporting::Reports::OrdersAndFulfillment::OrderCycleCustomerTotal # but these scenarios might be related it "handles a nil instead of an actual value" do order.line_items[0].update!(final_weight_volume: nil) - expect { report_table }.to raise_error(TypeError, "nil can't be coerced into Integer") + expect { report_table }.not_to raise_error(TypeError, "nil can't be coerced into Integer") end + it "it handles a missing value" do order.line_items[0].update!(final_weight_volume: "") - expect { report_table }.to raise_error(TypeError, "nil can't be coerced into Integer") + expect { report_table }.not_to raise_error(TypeError, "nil can't be coerced into Integer") end + it "handles a string input" do order.line_items[0].update!(final_weight_volume: "a string") expect { report_table }.not_to raise_error From 8e5404a268e335ae008aa3e7994ff4390d0be1de Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 5 Nov 2025 10:54:21 +0000 Subject: [PATCH 3/3] Replaces negative assertion with a positive assertion Adds test case on white spece Refactors to have tests as shared_examples --- ...order_cycle_customer_totals_report_spec.rb | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb index 97a4fd26b9..6a5de015be 100644 --- a/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb @@ -82,20 +82,17 @@ RSpec.describe Reporting::Reports::OrdersAndFulfillment::OrderCycleCustomerTotal # related to https://github.com/openfoodfoundation/openfoodnetwork/issues/13270 # not sure how we got DEPRECATION WARNING: Rails 7.0 has deprecated Enumerable.sum # but these scenarios might be related - it "handles a nil instead of an actual value" do - order.line_items[0].update!(final_weight_volume: nil) - expect { report_table }.not_to raise_error(TypeError, "nil can't be coerced into Integer") + shared_examples "the report is successfully generated" do |test_case, type| + it "if column final_weight_volume is #{test_case}" do + order.line_items[0].update!(final_weight_volume: type) + expect(report_table.length).to eq(2) + end end - it "it handles a missing value" do - order.line_items[0].update!(final_weight_volume: "") - expect { report_table }.not_to raise_error(TypeError, "nil can't be coerced into Integer") - end - - it "handles a string input" do - order.line_items[0].update!(final_weight_volume: "a string") - expect { report_table }.not_to raise_error - end + it_behaves_like "the report is successfully generated", "nil", nil + it_behaves_like "the report is successfully generated", "an empty value", "" + it_behaves_like "the report is successfully generated", "a white space", " " + it_behaves_like "the report is successfully generated", "a string", "kilograms" end end