mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
Gracefully handle empty string
This commit is contained in:
@@ -15,9 +15,11 @@ class WeightsAndMeasures
|
||||
|
||||
def system
|
||||
return "custom" unless scales = scales_for_variant_unit(ignore_available_units: true)
|
||||
return "custom" unless product_scale = @variant.product.variant_unit_scale
|
||||
|
||||
scales[product_scale.to_f]['system']
|
||||
product_scale = @variant.product.variant_unit_scale&.to_f
|
||||
return "custom" unless product_scale.present? && product_scale.positive?
|
||||
|
||||
scales[product_scale]['system']
|
||||
end
|
||||
|
||||
# @returns enumerable with label and value for select
|
||||
|
||||
@@ -91,7 +91,7 @@ RSpec.describe WeightsAndMeasures do
|
||||
expect(subject.system).to eq("custom")
|
||||
end
|
||||
|
||||
pending "when unit is valid, but scale is 0" do
|
||||
it "when unit is valid, but scale is 0" do
|
||||
allow(product).to receive(:variant_unit) { "weight" }
|
||||
allow(product).to receive(:variant_unit_scale) { 0.0 }
|
||||
expect(subject.system).to eq("custom")
|
||||
|
||||
Reference in New Issue
Block a user