Skip to content

Commit 42a5024

Browse files
committed
Fix monetized_attributes class discrepancy
Suppose we have a model ```ruby class Investment < ActiveRecord::Base monetize :value monetize :discounted_value end ``` and a subclass ```ruby class BadInvestment < Investment end ``` When we check the monetized_attributes of both the `Product` and `SpecialProduct` we get seemingly the same result: ```ruby 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`. This commit fixes the discrepancy, ensuring both are a `ActiveSupport::HashWithIndifferentAccess`.
1 parent 5fac874 commit 42a5024

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/money-rails/active_record/monetizable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ReadOnlyCurrencyException < MoneyRails::Error; end
1010

1111
module ClassMethods
1212
def monetized_attributes
13-
monetized_attributes = @monetized_attributes || {}
13+
monetized_attributes = @monetized_attributes || {}.with_indifferent_access
1414

1515
if superclass.respond_to?(:monetized_attributes)
1616
monetized_attributes.merge(superclass.monetized_attributes)

0 commit comments

Comments
 (0)