Permalink
Browse files

database schema respects the default currency

when default currency is changed. the amount column in the database
has a postfix of the subunit of the currency so set

likewise for the currency column as well. It also changes the
default value to the currencies iso code

add gem debugger for ruby 1.9 on MRI ruby

fix two failing tests where the default_currency is set to EUR
in spec/dummy/config/initializers/money.rb
  • Loading branch information...
1 parent 1fdd5fe commit f0394eb8b3c4b9ff5674ef5cc19fcc97b02416d5 @deepak deepak committed Jan 31, 2013
View
@@ -11,3 +11,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 f0394eb

Please sign in to comment.