Fix FrozenString error

An error was apparent in specs when trying to assign a string as the price. It's not a problem when submitting the form in the browser, I don't know why.

But in any case, it shouldn't be trying to modify a variable passed as a parameter.
This commit is contained in:
David Cook
2023-08-31 16:05:26 +10:00
parent b955cd8fee
commit 26d6dedd4d
2 changed files with 10 additions and 1 deletions

View File

@@ -44,7 +44,7 @@ module Spree
:'number.currency.format.delimiter'])
non_price_characters = /[^0-9\-#{separator}]/
# Strip everything else first
price.gsub!(non_price_characters, '')
price = price.gsub(non_price_characters, '')
# Then replace the locale-specific decimal separator with the standard separator if necessary
price.gsub!(separator, '.') unless separator == '.'

View File

@@ -25,5 +25,14 @@ module Spree
expect(expensive_variant.persisted?).to be true
end
end
context "with string" do
it "parses the price" do
variant.price = " 10.25 eur"
variant.save
expect(variant.reload.price).to eq 10.25
end
end
end
end