Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

database schema respects the default currency #75

Merged
merged 1 commit into from

2 participants

@deepak

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 and ruby-debug for ruby 1.8

spec/configuration_spec.rb
@@ -17,7 +17,7 @@
Money.ca_dollar(100).exchange_to("USD").should == Money.new(80, "USD")
end
- it "sets no_cents_if_whole value for formatted output globally" do
+ it "sets no_cents_if_whole value for formatted output globally", failing: true do
@alup Owner
alup added a note

failing: true should be removed

@deepak
deepak added a note

fixed. squashed on top of old commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@alup alup commented on the diff
@@ -11,3 +11,14 @@ end
platforms :ruby do
gem "sqlite3"
end
+
+platform :mri do
@alup Owner
alup added a note

All this block should be removed.

@deepak
deepak added a note

debugger gem supports MRI versions after 1.9.2-p290
https://github.com/cldwalker/debugger-ruby_core_source/tree/master/lib/debugger/ruby_core_source

we can add https://github.com/jruby/jruby-debug for JRuby.
I did not add it as i am not using JRuby now

@alup Owner
alup added a note

I don't want to add it right now as it is not related to the pull request.
Secondly, money-rails supports only ruby versions > 1.9.2 since September (I think).

@deepak
deepak added a note

ok. removed the gem for ruby 1.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@alup
Owner

I will gladly merge this if you fix the failing specs :)

@deepak deepak 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
f0394eb
@alup
Owner

super!!! thnx for your contribution :)

@deepak

@alup fixed failing tests.
PS: default_currency is set to EUR in spec/dummy/config/initializers/money.rb

@alup alup closed this
@alup alup reopened this
@alup alup merged commit 87ffa51 into RubyMoney:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 15, 2013
  1. @deepak

    database schema respects the default currency

    deepak authored
    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
This page is out of date. Refresh to see the latest.
View
9 Gemfile
@@ -11,3 +11,12 @@ end
platforms :ruby do
gem "sqlite3"
end
+
+platform :mri do
@alup Owner
alup added a note

All this block should be removed.

@deepak
deepak added a note

debugger gem supports MRI versions after 1.9.2-p290
https://github.com/cldwalker/debugger-ruby_core_source/tree/master/lib/debugger/ruby_core_source

we can add https://github.com/jruby/jruby-debug for JRuby.
I did not add it as i am not using JRuby now

@alup Owner
alup added a note

I don't want to add it right now as it is not related to the pull request.
Secondly, money-rails supports only ruby versions > 1.9.2 since September (I think).

@deepak
deepak added a note

ok. removed the gem for ruby 1.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ # gem "ruby-prof", "~> 0.11.2"
+
+ case RUBY_VERSION
+ when /^1.9/
+ gem 'debugger'
+ end
+end
View
16 lib/money-rails/configuration.rb
@@ -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,9 +20,15 @@ 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
@@ -29,6 +36,15 @@ 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):
View
4 spec/active_record/migration_extensions/schema_statements_spec.rb
@@ -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
View
4 spec/active_record/migration_extensions/table_spec.rb
@@ -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
View
8 spec/configuration_spec.rb
@@ -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
View
BIN  spec/dummy/db/test.sqlite3
Binary file not shown
Something went wrong with that request. Please try again.