spec/money/formatting_spec.rb in money-5.0.0 vs spec/money/formatting_spec.rb in money-5.1.0.beta1
- old
+ new
@@ -3,10 +3,11 @@
require "spec_helper"
describe Money, "formatting" do
BAR = '{ "priority": 1, "iso_code": "BAR", "iso_numeric": "840", "name": "Dollar with 4 decimal places", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": "," }'
+ INDIAN_BAR = '{ "priority": 1, "iso_code": "INDIAN_BAR", "iso_numeric": "840", "name": "Dollar with 4 decimal places", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": ",", "south_asian_number_formatting": true}'
EU4 = '{ "priority": 1, "iso_code": "EU4", "iso_numeric": "841", "name": "Euro with 4 decimal places", "symbol": "€", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "€", "decimal_mark": ",", "thousands_separator": "." }'
context "without i18n" do
subject { Money.empty("USD") }
@@ -130,11 +131,11 @@
# Brazilian Real
one_thousand["BRL"].should == "R$ 1.000,00"
# Other
- one_thousand["SEK"].should == "kr1,000.00"
+ one_thousand["SEK"].should == "1.000,00 kr"
one_thousand["GHC"].should == "₵1,000.00"
end
it "inserts commas into the result if the amount is sufficiently large" do
Money.us_dollar(1_000_000_000_12).format.should == "$1,000,000,000.12"
@@ -229,11 +230,11 @@
# Brazilian Real
one["BRL"].should == "R$ 1,00"
# Other
- one["SEK"].should == "kr1.00"
+ one["SEK"].should == "1,00 kr"
one["GHC"].should == "₵1.00"
end
specify "(:symbol => true) returns $ when currency code is not recognized" do
currency = Money::Currency.new("EUR")
@@ -242,11 +243,11 @@
end
specify "(:symbol => some non-Boolean value that evaluates to true) returns symbol based on the given currency code" do
Money.new(100, "GBP").format(:symbol => true).should == "£1.00"
Money.new(100, "EUR").format(:symbol => true).should == "€1,00"
- Money.new(100, "SEK").format(:symbol => true).should == "kr1.00"
+ Money.new(100, "SEK").format(:symbol => true).should == "1,00 kr"
end
specify "(:symbol => "", nil or false) returns the amount without a symbol" do
money = Money.new(100, "GBP")
money.format(:symbol => "").should == "1.00"
@@ -280,10 +281,22 @@
specify "(:separator => a separator string) works as documented" do
Money.us_dollar(100).format(:separator => ",").should == "$1,00"
end
end
+ describe ":south_asian_number_formatting delimiter" do
+ before(:each) do
+ Money::Currency.register(JSON.parse(INDIAN_BAR, :symbolize_names => true))
+ end
+
+ specify "(:south_asian_number_formatting => true) works as documented" do
+ Money.new(10000000, 'INR').format(:south_asian_number_formatting => true, :symbol => false).should == "1,00,000.00"
+ Money.new(1000000000, 'INDIAN_BAR').format(:south_asian_number_formatting => true, :symbol => false).should == "1,00,000.0000"
+ Money.new(10000000).format(:south_asian_number_formatting => true).should == "$1,00,000.00"
+ end
+ end
+
describe ":thousands_separator option" do
specify "(:thousands_separator => a thousands_separator string) works as documented" do
Money.us_dollar(100000).format(:thousands_separator => ".").should == "$1.000.00"
Money.us_dollar(200000).format(:thousands_separator => "").should == "$2000.00"
end
@@ -382,26 +395,28 @@
"1000.0".to_money("VND").format(:symbol => false).should == "1.000,0"
"-1000.0".to_money("VND").format(:symbol => false).should == "-1.000,0"
end
it "brute forces :subunit_to_unit = 100" do
- ("0.00".."9.99").each do |amt|
+ %w{0.00 0.01 1.00 1.01 5.67 9.99}.each do |amt|
amt.to_money("USD").format(:symbol => false).should == amt
end
- ("-0.01".."-9.99").each do |amt|
+ %w{-0.01 -1.00 -1.01 -5.67 -9.99}.each do |amt|
amt.to_money("USD").format(:symbol => false).should == amt
end
"1000.00".to_money("USD").format(:symbol => false).should == "1,000.00"
"-1000.00".to_money("USD").format(:symbol => false).should == "-1,000.00"
end
it "brute forces :subunit_to_unit = 1000" do
- ("0.000".."9.999").each do |amt|
+ %w{0.000 0.001 1.000 1.001 5.678 9.999}.each do |amt|
amt.to_money("IQD").format(:symbol => false).should == amt
end
- ("-0.001".."-9.999").each do |amt|
+
+ %w{-0.001 -1.000 -1.001 -5.678 -9.999}.each do |amt|
amt.to_money("IQD").format(:symbol => false).should == amt
end
+
"1000.000".to_money("IQD").format(:symbol => false).should == "1,000.000"
"-1000.000".to_money("IQD").format(:symbol => false).should == "-1,000.000"
end
end