mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #6926 from andrewpbrett/check-nan
Ensure unit_value is a number
This commit is contained in:
@@ -63,8 +63,8 @@ module Spree
|
||||
}
|
||||
|
||||
before_validation :set_cost_currency
|
||||
before_validation :update_weight_from_unit_value, if: ->(v) { v.product.present? }
|
||||
before_validation :ensure_unit_value
|
||||
before_validation :update_weight_from_unit_value, if: ->(v) { v.product.present? }
|
||||
|
||||
after_save :save_default_price
|
||||
after_save :update_units
|
||||
@@ -249,7 +249,8 @@ module Spree
|
||||
end
|
||||
|
||||
def ensure_unit_value
|
||||
return unless product&.variant_unit == "items" && unit_value.nil?
|
||||
Bugsnag.notify("Trying to set unit_value to NaN") if unit_value&.nan?
|
||||
return unless (product&.variant_unit == "items" && unit_value.nil?) || unit_value&.nan?
|
||||
|
||||
self.unit_value = 1.0
|
||||
end
|
||||
|
||||
@@ -733,5 +733,13 @@ module Spree
|
||||
expect(variant.unit_value).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
context "trying to set an invalid unit_value" do
|
||||
it "does not allow NaN" do
|
||||
variant.update(unit_value: Float::NAN)
|
||||
|
||||
expect(variant.reload.unit_value).to eq(1.0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user