Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Let default currency config accept currency without minor unit #92

Merged
merged 1 commit into from

2 participants

@ashchan

Currency as Japanese Yen doesn't have a minor unit, see RubyMoney/money#101

When setting such currency as default, the current implementation will raise NoMethodError since it tries to use the minor unit value.

This fixes that by checking if the unit value is present.

@alup
Owner

Thank you for this!

@alup alup merged commit 45d60b3 into RubyMoney:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 3 deletions.
  1. +2 −2 lib/money-rails/configuration.rb
  2. +14 −1 spec/configuration_spec.rb
View
4 lib/money-rails/configuration.rb
@@ -23,7 +23,7 @@ def configure
def default_currency
Money.default_currency
end
-
+
# Set default currency of money library
def default_currency=(currency_name)
Money.default_currency = Money::Currency.new(currency_name)
@@ -37,7 +37,7 @@ def register_currency=(currency_options)
end
def set_amount_column_for_default_currency!
- amount_column.merge! postfix: "_#{default_currency.subunit.downcase.pluralize}"
+ amount_column.merge! postfix: "_#{default_currency.subunit.downcase.pluralize}" if default_currency.subunit
end
def set_currency_column_for_default_currency!
View
15 spec/configuration_spec.rb
@@ -65,6 +65,19 @@
# Reset global setting
MoneyRails.default_currency = old_currency
end
-
+
+ it "accepts default currency which doesn't have minor unit" do
+ old_currency = MoneyRails.default_currency
+
+ expect {
+ MoneyRails.default_currency = :jpy
+ }.to_not raise_error
+
+ MoneyRails.amount_column[:postfix].should == "_cents"
+
+ # Reset global setting
+ MoneyRails.default_currency = old_currency
+ end
+
end
end
Something went wrong with that request. Please try again.