mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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:
@@ -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']
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user