Skip to content

Commit

Permalink
[SD-1461] fix money_methods for ruby version < 2.7 (#11373)
Browse files Browse the repository at this point in the history
* SD-1461 fix money_methods for ruby version < 3.0

* SD-1461 change approach
  • Loading branch information
KacperMekarski committed Oct 1, 2021
1 parent 60e2ab4 commit 55a22f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/app/models/concerns/spree/display_money.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def money_methods(*args)
define_method("display_#{method_name}") do |**args_list|
default_opts = respond_to?(:currency) ? { currency: currency } : {}

Spree::Money.new(send(method_name, **args_list), default_opts.merge(opts).merge(args_list.slice(:currency)))
amount = args_list.blank? ? send(method_name) : send(method_name, **args_list)

Spree::Money.new(amount, default_opts.merge(opts).merge(args_list.slice(:currency)))
end
end
end
Expand Down
1 change: 1 addition & 0 deletions core/spec/models/spree/concerns/display_money_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def total(currency:)
expect(test_class.new.display_total(currency: currency)).to eq Spree::Money.new(10.0, currency: currency)
end
end

context 'wrapped method accepts `currency` argument' do
let(:test_class) do
Class.new do
Expand Down

0 comments on commit 55a22f9

Please sign in to comment.