mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-04 07:09:14 +00:00
Update Spree::Price parsing to match LocalizedNumber.parse
Spree::Price parsing was returning 0.0 when given a an empty string as price, resulting in a variant being valid even if no price was given. It only happened if `Spree::LocalizedNumber` wasn't used. Spree::LocalizedNumber` return nil if given a blank number.
This commit is contained in:
@@ -38,6 +38,7 @@ module Spree
|
||||
|
||||
# strips all non-price-like characters from the price, taking into account locale settings
|
||||
def parse_price(price)
|
||||
return nil if price.blank?
|
||||
return price unless price.is_a?(String)
|
||||
|
||||
separator, _delimiter = I18n.t([:'number.currency.format.separator',
|
||||
|
||||
@@ -34,5 +34,25 @@ module Spree
|
||||
expect(variant.reload.price).to eq 10.25
|
||||
end
|
||||
end
|
||||
|
||||
describe "#price=" do
|
||||
subject { Spree::Price.new }
|
||||
|
||||
context "with a number" do
|
||||
it "returns the same number" do
|
||||
subject.price = 12.5
|
||||
|
||||
expect(subject.price).to eq(12.5)
|
||||
end
|
||||
end
|
||||
|
||||
context "with empty string" do
|
||||
it "sets the price to nil" do
|
||||
subject.price = ""
|
||||
|
||||
expect(subject.price).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user