spec/money/formatting_spec.rb in money-6.3.0 vs spec/money/formatting_spec.rb in money-6.4.0
- old
+ new
@@ -118,11 +118,11 @@
it "respects :subunit_to_unit currency property" do
expect(Money.new(10_00, "BHD").format).to eq "ب.د1.000"
end
it "does not display a decimal when :subunit_to_unit is 1" do
- expect(Money.new(10_00, "CLP").format).to eq "$1.000"
+ expect(Money.new(10_00, "VUV").format).to eq "Vt1,000"
end
it "respects the thousands_separator and decimal_mark defaults" do
one_thousand = Proc.new do |currency|
Money.new(1000_00, currency).format
@@ -167,10 +167,44 @@
it "inserts thousands separator into the result if the amount is sufficiently large and the currency symbol is at the end" do
expect(Money.euro(1_234_567_12).format).to eq "€1.234.567,12"
expect(Money.euro(1_234_567_12).format(:no_cents => true)).to eq "€1.234.567"
end
+ context 'when default_formatting_rules defines (display_free: true)' do
+ before do
+ Money.default_formatting_rules = { :display_free => "you won't pay a thing" }
+ end
+
+ after do
+ Money.default_formatting_rules = nil
+ end
+
+ context 'with no rule provided' do
+ it 'acknowledges default rule' do
+ expect(Money.new(0, 'USD').format).to eq "you won't pay a thing"
+ end
+ end
+
+ context 'with rule (display_free: false) provided' do
+ it 'acknowledges provided rule' do
+ expect(Money.new(0, 'USD').format(:display_free => false)).to eq '$0.00'
+ end
+ end
+ end
+
+ context 'when default_formatting_rules is not defined' do
+ before do
+ Money.default_formatting_rules = nil
+ end
+
+ context 'acknowledges provided rule' do
+ it 'acknowledges provided rule' do
+ expect(Money.new(100, 'USD').format(:with_currency => true)).to eq '$1.00 USD'
+ end
+ end
+ end
+
describe ":with_currency option" do
specify "(:with_currency option => true) works as documented" do
expect(Money.ca_dollar(100).format(:with_currency => true)).to eq "$1.00 CAD"
expect(Money.us_dollar(85).format(:with_currency => true)).to eq "$0.85 USD"
end
@@ -189,11 +223,11 @@
end
it "inserts thousand separators if symbol contains decimal mark and no_cents is true" do
expect(Money.new(100000000, "AMD").format(:no_cents => true)).to eq "1,000,000 դր."
expect(Money.new(100000000, "USD").format(:no_cents => true)).to eq "$1,000,000"
- expect(Money.new(100000000, "RUB").format(:no_cents => true)).to eq "1.000.000 р."
+ expect(Money.new(100000000, "RUB").format(:no_cents => true)).to eq "1.000.000 руб"
end
it "doesn't incorrectly format HTML" do
money = ::Money.new(1999, "RUB")
output = money.format(:html => true, :no_cents => true)
@@ -205,12 +239,12 @@
specify "(:no_cents_if_whole => true) works as documented" do
expect(Money.new(10000, "VUV").format(:no_cents_if_whole => true, :symbol => false)).to eq "10,000"
expect(Money.new(10034, "VUV").format(:no_cents_if_whole => true, :symbol => false)).to eq "10,034"
expect(Money.new(10000, "MGA").format(:no_cents_if_whole => true, :symbol => false)).to eq "2,000"
expect(Money.new(10034, "MGA").format(:no_cents_if_whole => true, :symbol => false)).to eq "2,006.4"
- expect(Money.new(10000, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "1.000"
- expect(Money.new(10034, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "1.003,4"
+ expect(Money.new(10000, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "10.000"
+ expect(Money.new(10034, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "10.034"
expect(Money.new(10000, "USD").format(:no_cents_if_whole => true, :symbol => false)).to eq "100"
expect(Money.new(10034, "USD").format(:no_cents_if_whole => true, :symbol => false)).to eq "100.34"
expect(Money.new(10000, "IQD").format(:no_cents_if_whole => true, :symbol => false)).to eq "10"
expect(Money.new(10034, "IQD").format(:no_cents_if_whole => true, :symbol => false)).to eq "10.034"
end
@@ -218,12 +252,12 @@
specify "(:no_cents_if_whole => false) works as documented" do
expect(Money.new(10000, "VUV").format(:no_cents_if_whole => false, :symbol => false)).to eq "10,000"
expect(Money.new(10034, "VUV").format(:no_cents_if_whole => false, :symbol => false)).to eq "10,034"
expect(Money.new(10000, "MGA").format(:no_cents_if_whole => false, :symbol => false)).to eq "2,000.0"
expect(Money.new(10034, "MGA").format(:no_cents_if_whole => false, :symbol => false)).to eq "2,006.4"
- expect(Money.new(10000, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "1.000,0"
- expect(Money.new(10034, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "1.003,4"
+ expect(Money.new(10000, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.000"
+ expect(Money.new(10034, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.034"
expect(Money.new(10000, "USD").format(:no_cents_if_whole => false, :symbol => false)).to eq "100.00"
expect(Money.new(10034, "USD").format(:no_cents_if_whole => false, :symbol => false)).to eq "100.34"
expect(Money.new(10000, "IQD").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.000"
expect(Money.new(10034, "IQD").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.034"
end
@@ -581,9 +615,49 @@
expect(Money.new(33310034, "BAR").format).to eq "$3,331.0034"
expect(Money.new(33310034, "EU4").format).to eq "€3.331,0034"
expect(Money.new(88833310034, "BAR").format).to eq "$8,883,331.0034"
expect(Money.new(88833310034, "EU4").format).to eq "€8.883.331,0034"
+ end
+
+ end
+
+ context "currencies with ambiguous signs" do
+
+ it "returns ambiguous signs when disambiguate is not set" do
+ expect(Money.new(1999_98, "USD").format).to eq("$1,999.98")
+ expect(Money.new(1999_98, "CAD").format).to eq("$1,999.98")
+ expect(Money.new(1999_98, "DKK").format).to eq("1.999,98 kr")
+ expect(Money.new(1999_98, "NOK").format).to eq("1.999,98 kr")
+ expect(Money.new(1999_98, "SEK").format).to eq("1 999,98 kr")
+ end
+
+ it "returns ambiguous signs when disambiguate is false" do
+ expect(Money.new(1999_98, "USD").format(disambiguate: false)).to eq("$1,999.98")
+ expect(Money.new(1999_98, "CAD").format(disambiguate: false)).to eq("$1,999.98")
+ expect(Money.new(1999_98, "DKK").format(disambiguate: false)).to eq("1.999,98 kr")
+ expect(Money.new(1999_98, "NOK").format(disambiguate: false)).to eq("1.999,98 kr")
+ expect(Money.new(1999_98, "SEK").format(disambiguate: false)).to eq("1 999,98 kr")
+ end
+
+ it "returns disambiguate signs when disambiguate: true" do
+ expect(Money.new(1999_98, "USD").format(disambiguate: true)).to eq("$1,999.98")
+ expect(Money.new(1999_98, "CAD").format(disambiguate: true)).to eq("C$1,999.98")
+ expect(Money.new(1999_98, "DKK").format(disambiguate: true)).to eq("1.999,98 DKK")
+ expect(Money.new(1999_98, "NOK").format(disambiguate: true)).to eq("1.999,98 NOK")
+ expect(Money.new(1999_98, "SEK").format(disambiguate: true)).to eq("1 999,98 SEK")
+ end
+
+ it "should never return an ambiguous format with disambiguate: true" do
+ formatted_results = {}
+
+ # When we format the same amount in all known currencies, disambiguate should return
+ # all different values
+ Money::Currency.all.each do |currency|
+ format = Money.new(1999_98, currency).format(disambiguate: true)
+ expect(formatted_results.keys).not_to include(format), "Format '#{format}' for #{currency} is ambiguous with currency #{formatted_results[format]}."
+ formatted_results[format] = currency
+ end
end
end
end