From 26d6dedd4d959fcf9158d72e38440623a1cfb34b Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 31 Aug 2023 16:05:26 +1000 Subject: [PATCH] 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. --- app/models/spree/price.rb | 2 +- spec/models/spree/price_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/spree/price.rb b/app/models/spree/price.rb index 9818ffd154..34344f62f0 100644 --- a/app/models/spree/price.rb +++ b/app/models/spree/price.rb @@ -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 == '.' diff --git a/spec/models/spree/price_spec.rb b/spec/models/spree/price_spec.rb index 9c4739097d..1b4898c2a2 100644 --- a/spec/models/spree/price_spec.rb +++ b/spec/models/spree/price_spec.rb @@ -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