Permalink
Browse files

Reset global settings to avoid unexpected behavior

  • Loading branch information...
alup committed Feb 17, 2013
1 parent 6328733 commit d5381a299df77fe834512ce9deada0a3d05e2b4d
Showing with 15 additions and 1 deletion.
  1. +10 −0 spec/active_record/monetizable_spec.rb
  2. +5 −1 spec/configuration_spec.rb
@@ -128,21 +128,31 @@ class Sub < Product; end
end
it "uses i18n currency format when validating" do
+ old_locale = I18n.locale
+
I18n.locale = "en-GB"
Money.default_currency = Money::Currency.find('EUR')
"12.00".to_money.should == Money.new(1200, :eur)
transaction = Transaction.new(amount: "12.00", tax: "13.00")
transaction.amount_cents.should == 1200
transaction.valid?.should be_true
+
+ # reset locale setting
+ I18n.locale = old_locale
end
it "defaults to Money::Currency format when no I18n information is present" do
+ old_locale = I18n.locale
+
I18n.locale = "zxsw"
Money.default_currency = Money::Currency.find('EUR')
"12,00".to_money.should == Money.new(1200, :eur)
transaction = Transaction.new(amount: "12,00", tax: "13,00")
transaction.amount_cents.should == 1200
transaction.valid?.should be_true
+
+ # reset locale setting
+ I18n.locale = old_locale
end
it "doesn't allow nil by default" do
@@ -52,10 +52,14 @@
end
it "changes the amount and currency column settings based on the default currency" do
+ old_currency = MoneyRails.default_currency
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
+
+ # Reset global setting
+ MoneyRails.default_currency = old_currency
end
end

0 comments on commit d5381a2

Please sign in to comment.