Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix row currency serialization

  • Loading branch information...
commit 198fc5105c6ce8dad391f7e63919b497509b1bf1 1 parent 5c42a95
@alup alup authored
View
2  lib/money-rails/active_record/monetizable.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
View
8 spec/active_record/monetizable_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.