Skip to content

Commit

Permalink
Merge pull request #92 from ashchan/master
Browse files Browse the repository at this point in the history
Let default currency config accept currency without minor unit
  • Loading branch information
alup committed Mar 25, 2013
2 parents a315524 + 9b4f8fd commit 45d60b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/money-rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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!
Expand Down
15 changes: 14 additions & 1 deletion spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 45d60b3

Please sign in to comment.