Skip to content

Commit

Permalink
Merge pull request RubyMoney#225 from featurist/master
Browse files Browse the repository at this point in the history
Fix currency assumption when parsing $ with a non-USD default currency
  • Loading branch information
semmons99 committed Oct 25, 2012
2 parents 0b0bcfe + af9b4b0 commit 0222573
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ Tobias Luetke
Tobias Schmidt
Tom Lianza
Бродяной Александр
Adrian Longley
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/money/money/parsing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions spec/money/parsing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/support/default_currency_helper.rb
Original file line number Diff line number Diff line change
@@ -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 0222573

Please sign in to comment.