From a60b4a41c569ae7f582fb9a6e8aebd13384e3c29 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Wed, 7 Apr 2021 18:31:15 -0700 Subject: [PATCH] guard against variants that use items but have scales --- app/services/weights_and_measures.rb | 2 +- spec/services/weights_and_measures_spec.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/services/weights_and_measures.rb b/app/services/weights_and_measures.rb index eaf66b3ec4..c2bc8c313c 100644 --- a/app/services/weights_and_measures.rb +++ b/app/services/weights_and_measures.rb @@ -14,7 +14,7 @@ class WeightsAndMeasures end def system - scales = scales_for_variant_unit + return "custom" unless scales = scales_for_variant_unit return "custom" unless product_scale = @variant.product.variant_unit_scale scales[product_scale.to_f]['system'] diff --git a/spec/services/weights_and_measures_spec.rb b/spec/services/weights_and_measures_spec.rb index 435ac0f5e4..c6f98e6e5a 100644 --- a/spec/services/weights_and_measures_spec.rb +++ b/spec/services/weights_and_measures_spec.rb @@ -37,11 +37,17 @@ describe WeightsAndMeasures do end context "items" do - it "when scale is for items" do + it "when variant unit is items" do allow(product).to receive(:variant_unit) { "items" } allow(product).to receive(:variant_unit_scale) { nil } expect(subject.system).to eq("custom") end + + it "when variant unit is items, even if the scale is present" do + allow(product).to receive(:variant_unit) { "items" } + allow(product).to receive(:variant_unit_scale) { 1.0 } + expect(subject.system).to eq("custom") + end end end