RubyMoney/money-rails — pull request #62 by esdras (2012-12-17 00:06:03+00:00)
Title: fixed error caused by ActiveSupport::HashWithIndifferentAccess

Hey, how is it going?

I got this error today in my rails up that uses mongoid v3:

```ruby
Failure/Error: subject.add(variant: variant)
NoMethodError:
undefined method `symbolize_keys!' for {"cents"=>0, "currency_iso"=>"BRL"}:ActiveSupport::HashWithIndifferentAccess
```

It turns out the error was occurring in this method:

```ruby
def self.factory(product, variant = nil)
variant ||= product.default_variant
attributes = product.attributes.dup
attributes.delete(:variants)
new(attributes).tap do |ep|
ep.id = product.id
ep.build_variant(variant.attributes.dup)
ep.variant.id = variant.id
ep.images = product.images
ep.original_product_id = product.id
ep.original_variant_id = variant.id
end
end
```

Digging I found that the exception was raised here:
```ruby
def mongoize(object)
case
when object.is_a?(Money) then object.mongoize
when object.is_a?(Hash) then
object.symbolize_keys! if object.respond_to?(:symbolize_keys!)
::Money.new(object[:cents], object[:currency_iso]).mongoize
when object.respond_to?(:to_money) then
object.to_money.mongoize
else object
end
end
```

I don't know if this is the right approach, but here it goes.

Let me know if you need any help.