RubyMoney / money-rails

Integration of RubyMoney - Money with Rails
MIT License
1.79k stars 386 forks source link

Fix monetized_attributes class discrepancy #681

Closed Neilos closed 6 months ago

Neilos commented 9 months ago

Suppose we have a model

class Investment < ActiveRecord::Base
  monetize :value
  monetize :discounted_value
end

and a subclass

class BadInvestment < Investment
end

When we check the monetized_attributes of both the Product and SpecialProduct we get seemingly the same result:

Investment.monetized_attributes
# => {
  'value' => 'value_cents',
  'discounted_value' => 'discounted_value_cents',
}

BadInvestment.monetized_attributes
# => {
  'value' => 'value_cents',
  'discounted_value' => 'discounted_value_cents',
}

...but when we check the class of the monetized_attributes we can see that one is a ActiveSupport::HashWithIndifferentAccess while the other is a Hash.

Investment.monetized_attributes.class
# => ActiveSupport::HashWithIndifferentAccess

BadInvestment.monetized_attributes
# => Hash

This pull request fixes the discrepancy, ensuring both are a ActiveSupport::HashWithIndifferentAccess.

semmons99 commented 6 months ago

ty