From 96bcde61a33812e0fdfcd26a40536c8ae0e25272 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 8 Mar 2021 10:25:16 +0100 Subject: [PATCH] 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`. ``` --- lib/spree/money.rb | 4 ++-- spec/lib/spree/money_spec.rb | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/spree/money.rb b/lib/spree/money.rb index d0d3e581e9..7ac0bd2722 100644 --- a/lib/spree/money.rb +++ b/lib/spree/money.rb @@ -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 diff --git a/spec/lib/spree/money_spec.rb b/spec/lib/spree/money_spec.rb index 9b7ad8e534..e1ab7663af 100644 --- a/spec/lib/spree/money_spec.rb +++ b/spec/lib/spree/money_spec.rb @@ -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( + "10.00 " + ) end + # rubocop:enable Layout/LineLength end end