Permalink
Browse files

Merge pull request #62 from esdras/master

fixed error caused by ActiveSupport::HashWithIndifferentAccess
  • Loading branch information...
2 parents 8e96efb + c0f3005 commit b0bfc1db36de269cc10eb9b275d7a22541e60a8e @alup alup committed Dec 20, 2012
Showing with 15 additions and 1 deletion.
  1. +1 −1 lib/money-rails/mongoid/three.rb
  2. +14 −0 spec/mongoid/three_spec.rb
View
2 lib/money-rails/mongoid/three.rb
@@ -27,7 +27,7 @@ def mongoize(object)
case
when object.is_a?(Money) then object.mongoize
when object.is_a?(Hash) then
- object.symbolize_keys!
+ 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
View
14 spec/mongoid/three_spec.rb
@@ -6,6 +6,10 @@
let!(:priceable) { Priceable.create(:price => Money.new(100, 'EUR')) }
let!(:priceable_from_num) { Priceable.create(:price => 1) }
let!(:priceable_from_string) { Priceable.create(:price => '1 EUR' )}
+ let!(:priceable_from_hash) { Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"} )}
+ let!(:priceable_from_hash_with_indifferent_access) {
+ Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"}.with_indifferent_access)
+ }
context "mongoize" do
it "mongoizes correctly a Money object to a hash of cents and currency" do
@@ -22,6 +26,16 @@
priceable_from_string.price.cents.should == 100
priceable_from_string.price.currency.should == Money::Currency.find('EUR')
end
+
+ it "mongoizes correctly a hash of cents and currency" do
+ priceable_from_hash.price.cents.should == 100
+ priceable_from_hash.price.currency.should == Money::Currency.find('EUR')
+ end
+
+ it "mongoizes correctly a HashWithIndifferentAccess of cents and currency" do
+ priceable_from_hash_with_indifferent_access.price.cents.should == 100
+ priceable_from_hash_with_indifferent_access.price.currency.should == Money::Currency.find('EUR')
+ end
end
context "demongoize" do

0 comments on commit b0bfc1d

Please sign in to comment.