Permalink
Browse files

Fix row currency serialization

  • Loading branch information...
1 parent 5c42a95 commit 198fc5105c6ce8dad391f7e63919b497509b1bf1 @alup alup committed Jul 10, 2012
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/money-rails/active_record/monetizable.rb
  2. +8 −0 spec/active_record/monetizable_spec.rb
@@ -70,7 +70,7 @@ def monetize(field, *args)
end
send("#{subunit_name}=", money.try(:cents))
- send("#{instance_currency_name}=", money.try(:currency)) if self.respond_to?("#{instance_currency_name}=")
+ send("#{instance_currency_name}=", money.try(:currency).try(:iso_code)) if self.respond_to?("#{instance_currency_name}=")
instance_variable_set "@#{name}", money
end
@@ -181,6 +181,14 @@
@dummy_product2 = DummyProduct.create(:price_cents => 2600) # nil currency
end
+ it "serializes correctly the currency to a new instance of model" do
+ d = DummyProduct.new
+ d.price = Money.new(10, "EUR")
+ d.save!
+ d.reload
+ d.currency.should == "EUR"
+ end
+
it "overrides default currency with the value of row currency" do
@transaction.amount.currency.should == Money::Currency.find(:usd)
end

0 comments on commit 198fc51

Please sign in to comment.