guard against variants that use items but have scales

This commit is contained in:
Andy Brett
2021-04-07 18:31:15 -07:00
parent 52c7abf1c0
commit a60b4a41c5
2 changed files with 8 additions and 2 deletions

View File

@@ -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']

View File

@@ -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