Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #225 from featurist/master

Fix currency assumption when parsing $ with a non-USD default currency
  • Loading branch information...
commit 02225730bd39544f8cecf0fbec2f9b03d5a03d60 2 parents 0b0bcfe + af9b4b0
@semmons99 semmons99 authored
View
1  AUTHORS
@@ -60,3 +60,4 @@ Tobias Luetke
Tobias Schmidt
Tom Lianza
Бродяной Александр
+Adrian Longley
View
1  CHANGELOG.md
@@ -2,6 +2,7 @@
## master
+- Fix currency assumption when parsing $ with a non-USD default currency.
- Changed the Bulgarian lev symbol position from before the amount to after the amount.
- Changed the symbol and html entity for INR. It is now "₹" instead of "₨".
- Added Money::Currency.analyze for determining potential currencies for a given string using powereful algorithms - will detect symbols, iso codes and names even if mixed with text.
View
2  lib/money/money/parsing.rb
@@ -42,7 +42,7 @@ def parse(input, currency = nil)
# from the stated currency string
c = if Money.assume_from_symbol && i =~ /^(\$|€|£)/
case i
- when /^$/ then "USD"
+ when /^\$/ then "USD"
when /^€/ then "EUR"
when // then "GBP"
end
View
6 spec/money/parsing_spec.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
3  spec/spec_helper.rb
@@ -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
View
13 spec/support/default_currency_helper.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.