mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Fix Money deprecation warning with :html_wrap
This fixes the following deprecation warning ``` [DEPRECATION] `html` is deprecated - use `html_wrap` instead. Please note that `html_wrap` will wrap all parts of currency and if you use `with_currency` option, currency element class changes from `currency` to `money-currency`. ```
This commit is contained in:
@@ -27,9 +27,9 @@ module Spree
|
||||
@money.format(@options)
|
||||
end
|
||||
|
||||
def to_html(options = { html: true })
|
||||
def to_html(options = { html_wrap: true })
|
||||
output = @money.format(@options.merge(options))
|
||||
if options[:html]
|
||||
if options[:html_wrap]
|
||||
# 1) prevent blank, breaking spaces
|
||||
# 2) prevent escaping of HTML character entities
|
||||
output = output.sub(" ", " ").html_safe
|
||||
|
||||
@@ -25,13 +25,13 @@ describe Spree::Money do
|
||||
|
||||
context "with currency" do
|
||||
it "passed in option" do
|
||||
money = Spree::Money.new(10, with_currency: true, html: false)
|
||||
money = Spree::Money.new(10, with_currency: true, html_wrap: false)
|
||||
expect(money.to_s).to eq("$10.00 USD")
|
||||
end
|
||||
|
||||
it "config option" do
|
||||
Spree::Config[:display_currency] = true
|
||||
money = Spree::Money.new(10, html: false)
|
||||
money = Spree::Money.new(10, html_wrap: false)
|
||||
expect(money.to_s).to eq("$10.00 USD")
|
||||
end
|
||||
end
|
||||
@@ -53,14 +53,14 @@ describe Spree::Money do
|
||||
context "currency parameter" do
|
||||
context "when currency is specified in Canadian Dollars" do
|
||||
it "uses the currency param over the global configuration" do
|
||||
money = Spree::Money.new(10, currency: 'CAD', with_currency: true, html: false)
|
||||
money = Spree::Money.new(10, currency: 'CAD', with_currency: true, html_wrap: false)
|
||||
expect(money.to_s).to eq("$10.00 CAD")
|
||||
end
|
||||
end
|
||||
|
||||
context "when currency is specified in Japanese Yen" do
|
||||
it "uses the currency param over the global configuration" do
|
||||
money = Spree::Money.new(100, currency: 'JPY', html: false)
|
||||
money = Spree::Money.new(100, currency: 'JPY', html_wrap: false)
|
||||
expect(money.to_s).to eq("¥100")
|
||||
end
|
||||
end
|
||||
@@ -68,18 +68,18 @@ describe Spree::Money do
|
||||
|
||||
context "symbol positioning" do
|
||||
it "passed in option" do
|
||||
money = Spree::Money.new(10, symbol_position: :after, html: false)
|
||||
money = Spree::Money.new(10, symbol_position: :after, html_wrap: false)
|
||||
expect(money.to_s).to eq("10.00 $")
|
||||
end
|
||||
|
||||
it "passed in option string" do
|
||||
money = Spree::Money.new(10, symbol_position: "after", html: false)
|
||||
money = Spree::Money.new(10, symbol_position: "after", html_wrap: false)
|
||||
expect(money.to_s).to eq("10.00 $")
|
||||
end
|
||||
|
||||
it "config option" do
|
||||
Spree::Config[:currency_symbol_position] = :after
|
||||
money = Spree::Money.new(10, html: false)
|
||||
money = Spree::Money.new(10, html_wrap: false)
|
||||
expect(money.to_s).to eq("10.00 $")
|
||||
end
|
||||
|
||||
@@ -118,10 +118,14 @@ describe Spree::Money do
|
||||
expect(money.to_s).to eq("1.000.00 €")
|
||||
end
|
||||
|
||||
# rubocop:disable Layout/LineLength
|
||||
it "formats as HTML if asked (nicely) to" do
|
||||
money = Spree::Money.new(10)
|
||||
# The HTMLified version of the euro sign
|
||||
expect(money.to_html).to eq("10.00 €")
|
||||
expect(money.to_html).to eq(
|
||||
"<span class=\"money-whole\">10</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span> <span class=\"money-currency-symbol\">€</span>"
|
||||
)
|
||||
end
|
||||
# rubocop:enable Layout/LineLength
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user