Permalink
Browse files

Merge pull request #75 from deepak/feature/support-inr-paise

database schema respects the default currency
  • Loading branch information...
2 parents 1cc92f8 + f0394eb commit 87ffa513a1078a1be2d5667449c9122dfa278861 @alup alup committed Feb 15, 2013
View
@@ -13,3 +13,12 @@ end
platforms :ruby do
gem "sqlite3"
end
+
+platform :mri do
+ # gem "ruby-prof", "~> 0.11.2"
+
+ case RUBY_VERSION
+ when /^1.9/
+ gem 'debugger'
+ end
+end
@@ -1,5 +1,6 @@
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/module/attribute_accessors'
+require 'active_support/core_ext/string/inflections'
module MoneyRails
@@ -19,16 +20,31 @@ def configure
# Configuration parameters
+ 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)
+ set_amount_column_for_default_currency!
+ set_currecy_column_for_default_currency!
end
# Register a custom currency
def register_currency=(currency_options)
Money::Currency.register(currency_options)
end
+ def set_amount_column_for_default_currency!
+ amount_column.merge! postfix: "_#{default_currency.subunit.downcase.pluralize}"
+ end
+
+ def set_currecy_column_for_default_currency!
+ iso_code = default_currency.iso_code
+ currency_column.merge! default: iso_code
+ end
+
# Set default bank object
#
# example (given that eu_central_bank is in Gemfile):
@@ -44,7 +44,9 @@ class Item < ActiveRecord::Base; end
describe 'currency' do
subject { Item.columns_hash['price_currency'] }
- its (:default) { should eq 'USD' }
+ # set in spec/dummy/config/initializers/money.rb
+ its (:default) { should eq 'EUR' }
+
its (:null) { should be_false }
its (:type) { should eq :string }
end
@@ -45,7 +45,9 @@ class Item < ActiveRecord::Base; end
describe 'currency' do
subject { Item.columns_hash['price_currency'] }
- its (:default) { should eq 'USD' }
+ # set in spec/dummy/config/initializers/money.rb
+ its (:default) { should eq 'EUR' }
+
its (:null) { should be_false }
its (:type) { should eq :string }
end
@@ -50,5 +50,13 @@
# Reset global setting
MoneyRails.symbol = nil
end
+
+ it "changes the amount and currency column settings based on the default currency" do
+ MoneyRails.default_currency = :inr
+
+ MoneyRails.amount_column[:postfix].should == "_#{MoneyRails.default_currency.subunit.downcase.pluralize}"
+ MoneyRails.currency_column[:default].should == MoneyRails.default_currency.iso_code
+ end
+
end
end
Binary file not shown.

0 comments on commit 87ffa51

Please sign in to comment.