mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Don't validate numericality if blank
This avoids unnecessary second message when left blank: > can't be blank > is not a number Ok this is a little confusing. Why is there a separate presence check above, and why is it only for measurable units, when we still require a number for _all_ units? Because, for 'items', we allow a blank value then auto-set it to 1. I don't know if it's really necessary, but that's how it currently works...
This commit is contained in:
@@ -69,7 +69,7 @@ module Spree
|
||||
%w(weight volume).include?(variant.product&.variant_unit)
|
||||
}
|
||||
|
||||
validates :unit_value, numericality: { greater_than: 0 }
|
||||
validates :unit_value, numericality: { greater_than: 0 }, allow_blank: true
|
||||
validates :price, numericality: { greater_than_or_equal_to: 0 }
|
||||
|
||||
validates :unit_description, presence: true, if: ->(variant) {
|
||||
|
||||
@@ -307,7 +307,7 @@ describe '
|
||||
|
||||
click_button 'Save Changes', match: :first
|
||||
expect(page.find("#status-message"))
|
||||
.to have_content "Variant unit value can't be blank Variant unit value is not a number"
|
||||
.to have_content "Variant unit value can't be blank"
|
||||
end
|
||||
|
||||
it "creating a variant with unit value is: '120g' and 'on_demand' checked" do
|
||||
@@ -323,7 +323,7 @@ describe '
|
||||
|
||||
click_button 'Save Changes', match: :first
|
||||
expect(page.find("#status-message"))
|
||||
.to have_content "Variant unit value can't be blank Variant unit value is not a number"
|
||||
.to have_content "Variant unit value can't be blank"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user