Skip to content

Commit

Permalink
Money#format does not display the symbol if :symbol is '', nil or false.
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Feb 21, 2009
1 parent f6a90c1 commit 87af801
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/money/money.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,15 @@ def format(*rules)
end
end

symbol = rules[:symbol] ? rules[:symbol].empty? ? "$" : rules[:symbol] : "$"
if rules.has_key?(:symbol)
if rules[:symbol]
symbol = rules[:symbol]
else
symbol = ""
end
else
symbol = "$"
end

if rules[:no_cents]
formatted = sprintf("#{symbol}%d", cents.to_f / 100)
Expand Down
2 changes: 1 addition & 1 deletion money.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "money"
s.version = "2.1.2"
s.version = "2.1.3"
s.summary = "Money and currency exchange support library"
s.email = "hongli@phusion.nl"
s.homepage = "http://money.rubyforge.org/"
Expand Down
7 changes: 7 additions & 0 deletions test/money_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@
Money.new(100, :currency => "GBP").format(:symbol => "£").should == "£1.00"
end

specify "#format with :symbol == "", nil or false returns the amount without a symbol" do
money = Money.new(100, :currency => "GBP")
money.format(:symbol => "").should == "1.00"
money.format(:symbol => nil).should == "1.00"
money.format(:symbol => false).should == "1.00"
end

specify "#format(:html => true) works as documented" do
string = Money.ca_dollar(570).format(:html => true, :with_currency => true)
string.should == "$5.70 <span class=\"currency\">CAD</span>"
Expand Down

0 comments on commit 87af801

Please sign in to comment.