mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Spec fix LocalisedNumber validation to allow negative number
As part of this PR https://github.com/openfoodfoundation/openfoodnetwork/pull/10329 LocalisedNumber validation was tightened, but that means negative number were not valid anymore. This commit has been cherry-picked after this fix has already been applied. Now we just change the order of characters in the regex because humans are used to reading the minus at the beginning of the number. But this change doesn't change the logic at all.
This commit is contained in:
committed by
Maikel Linke
parent
0442f2da7e
commit
d715b6b3bb
@@ -45,7 +45,7 @@ module Spree
|
||||
def self.valid_localizable_number?(number)
|
||||
return true unless number.is_a?(String) || number.respond_to?(:to_d)
|
||||
# Invalid if only two digits between dividers, or if any non-number characters
|
||||
return false if number.to_s =~ /[.,]\d{2}[.,]/ || number.to_s =~ /[^0-9,.-]+/
|
||||
return false if number.to_s =~ /[.,]\d{2}[.,]/ || number.to_s =~ /[^-0-9,.]+/
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
@@ -58,6 +58,12 @@ describe Spree::LocalizedNumber do
|
||||
it "returns true" do
|
||||
expect(described_class.valid_localizable_number?(1599.99)).to eql true
|
||||
end
|
||||
|
||||
context "with a negative number" do
|
||||
it "returns true" do
|
||||
expect(described_class.valid_localizable_number?(-1599.99)).to eql true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with letters" do
|
||||
|
||||
Reference in New Issue
Block a user