Merge pull request #7349 from andrewpbrett/fix-unit-price-nil-method

Guard against variants that use items but have scales
This commit is contained in:
Pau Pérez Fabregat
2021-04-08 09:56:48 +02:00
committed by GitHub
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