Permalink
Browse files

Expose bug in currency assumption where $ always parses as default

  • Loading branch information...
1 parent 0b0bcfe commit 4143cf989b2531cb2f65995045484390be20c588 @adiel adiel committed Oct 18, 2012
Showing with 20 additions and 2 deletions.
  1. +4 −2 spec/money/parsing_spec.rb
  2. +3 −0 spec/spec_helper.rb
  3. +13 −0 spec/support/default_currency_helper.rb
@@ -27,8 +27,10 @@
before do
Money.assume_from_symbol = true
end
- it "parses formatted inputs with the currency passed as a symbol" do
- Money.parse("$5.95").should == Money.new(595, 'USD')
+ it "parses formatted inputs with the currency passed as a symbol" do
+ with_default_currency("EUR") do
+ Money.parse("$5.95").should == Money.new(595, 'USD')
+ end
Money.parse("€5.95").should == Money.new(595, 'EUR')
Money.parse(" €5.95 ").should == Money.new(595, 'EUR')
Money.parse("£9.99").should == Money.new(999, 'GBP')
View
@@ -1,8 +1,11 @@
+$LOAD_PATH.unshift File.dirname(__FILE__)
require 'rspec'
require 'money'
+require 'support/default_currency_helper'
RSpec.configure do |c|
c.order = "rand"
+ c.include DefaultCurrencyHelper
end
def silence_warnings
@@ -0,0 +1,13 @@
+module DefaultCurrencyHelper
+
+ def with_default_currency(iso_code)
+ original_default = Money.default_currency
+ begin
+ Money.default_currency = Money::Currency.new(iso_code)
+ yield
+ ensure
+ Money.default_currency = original_default
+ end
+ end
+
+end

0 comments on commit 4143cf9

Please sign in to comment.