money 6.7.1 → 6.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -1
- data/.travis.yml +15 -6
- data/AUTHORS +5 -0
- data/CHANGELOG.md +98 -3
- data/Gemfile +13 -4
- data/LICENSE +2 -0
- data/README.md +64 -44
- data/config/currency_backwards_compatible.json +30 -0
- data/config/currency_iso.json +135 -59
- data/config/currency_non_iso.json +66 -2
- data/lib/money.rb +0 -13
- data/lib/money/bank/variable_exchange.rb +9 -22
- data/lib/money/currency.rb +33 -39
- data/lib/money/currency/heuristics.rb +1 -144
- data/lib/money/currency/loader.rb +1 -1
- data/lib/money/locale_backend/base.rb +7 -0
- data/lib/money/locale_backend/errors.rb +6 -0
- data/lib/money/locale_backend/i18n.rb +24 -0
- data/lib/money/locale_backend/legacy.rb +28 -0
- data/lib/money/money.rb +106 -139
- data/lib/money/money/allocation.rb +37 -0
- data/lib/money/money/arithmetic.rb +31 -28
- data/lib/money/money/constructors.rb +1 -2
- data/lib/money/money/formatter.rb +397 -0
- data/lib/money/money/formatting_rules.rb +120 -0
- data/lib/money/money/locale_backend.rb +20 -0
- data/lib/money/rates_store/memory.rb +1 -2
- data/lib/money/version.rb +1 -1
- data/money.gemspec +10 -16
- data/spec/bank/variable_exchange_spec.rb +7 -3
- data/spec/currency/heuristics_spec.rb +2 -153
- data/spec/currency_spec.rb +44 -3
- data/spec/locale_backend/i18n_spec.rb +62 -0
- data/spec/locale_backend/legacy_spec.rb +74 -0
- data/spec/money/allocation_spec.rb +130 -0
- data/spec/money/arithmetic_spec.rb +184 -90
- data/spec/money/constructors_spec.rb +0 -12
- data/spec/money/formatting_spec.rb +296 -179
- data/spec/money/locale_backend_spec.rb +14 -0
- data/spec/money_spec.rb +159 -26
- data/spec/rates_store/memory_spec.rb +13 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/support/shared_examples/money_examples.rb +14 -0
- metadata +32 -40
- data/lib/money/money/formatting.rb +0 -418
@@ -7,18 +7,6 @@ describe Money::Constructors do
|
|
7
7
|
expect(Money.empty).to eq Money.new(0)
|
8
8
|
end
|
9
9
|
|
10
|
-
it "memoizes the result" do
|
11
|
-
expect(Money.empty.object_id).to eq Money.empty.object_id
|
12
|
-
end
|
13
|
-
|
14
|
-
it "memoizes a result for each currency" do
|
15
|
-
expect(Money.empty(:cad).object_id).to eq Money.empty(:cad).object_id
|
16
|
-
end
|
17
|
-
|
18
|
-
it "doesn't allow money to be modified for a currency" do
|
19
|
-
expect(Money.empty).to be_frozen
|
20
|
-
end
|
21
|
-
|
22
10
|
it "instantiates a subclass when inheritance is used" do
|
23
11
|
special_money_class = Class.new(Money)
|
24
12
|
expect(special_money_class.empty).to be_a special_money_class
|
@@ -18,13 +18,26 @@ describe Money, "formatting" do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
context 'without locale_backend' do
|
22
|
+
before { Money.locale_backend = nil }
|
23
|
+
after { Money.locale_backend = :legacy }
|
24
|
+
|
25
|
+
subject(:money) { Money.new(1099_99, 'USD') }
|
26
|
+
|
27
|
+
it 'falls back to using defaults' do
|
28
|
+
expect(money.thousands_separator).to eq('')
|
29
|
+
expect(money.decimal_mark).to eq('.')
|
30
|
+
expect(money.format).to eq('$1099.99')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
21
34
|
context "with i18n but use_i18n = false" do
|
22
35
|
before :each do
|
23
36
|
reset_i18n
|
24
37
|
I18n.locale = :de
|
25
38
|
I18n.backend.store_translations(
|
26
39
|
:de,
|
27
|
-
:
|
40
|
+
number: { currency: { format: { delimiter: ".", separator: "," } } }
|
28
41
|
)
|
29
42
|
Money.use_i18n = false
|
30
43
|
end
|
@@ -58,7 +71,7 @@ describe Money, "formatting" do
|
|
58
71
|
I18n.locale = :de
|
59
72
|
I18n.backend.store_translations(
|
60
73
|
:de,
|
61
|
-
:
|
74
|
+
number: { format: { delimiter: ".", separator: "," } }
|
62
75
|
)
|
63
76
|
end
|
64
77
|
|
@@ -79,7 +92,7 @@ describe Money, "formatting" do
|
|
79
92
|
I18n.locale = :de
|
80
93
|
I18n.backend.store_translations(
|
81
94
|
:de,
|
82
|
-
:
|
95
|
+
number: { currency: { format: { delimiter: ".", separator: "," } } }
|
83
96
|
)
|
84
97
|
end
|
85
98
|
|
@@ -100,24 +113,24 @@ describe Money, "formatting" do
|
|
100
113
|
I18n.locale = :de
|
101
114
|
I18n.backend.store_translations(
|
102
115
|
:de,
|
103
|
-
:
|
116
|
+
number: { currency: { symbol: { CAD: "CAD$" } } }
|
104
117
|
)
|
105
118
|
end
|
106
119
|
|
107
120
|
subject(:money) { Money.empty("CAD") }
|
108
121
|
|
109
122
|
it "should use 'CAD$' as the currency symbol" do
|
110
|
-
expect(money.format(:
|
123
|
+
expect(money.format(translate: true)).to eq("CAD$0.00")
|
111
124
|
end
|
112
125
|
end
|
113
126
|
|
114
127
|
context "with overridden i18n settings" do
|
115
128
|
it "should respect explicit overriding of thousands_separator/delimiter when decimal_mark/separator collide and there’s no decimal component for currencies that have no subunit" do
|
116
|
-
expect(Money.new(300_000, 'ISK').format(:
|
129
|
+
expect(Money.new(300_000, 'ISK').format(thousands_separator: ".", decimal_mark: ',')).to eq "kr300.000"
|
117
130
|
end
|
118
131
|
|
119
132
|
it "should respect explicit overriding of thousands_separator/delimiter when decimal_mark/separator collide and there’s no decimal component for currencies with subunits that drop_trailing_zeros" do
|
120
|
-
expect(Money.new(300_000, 'USD').format(:
|
133
|
+
expect(Money.new(300_000, 'USD').format(thousands_separator: ".", decimal_mark: ',', drop_trailing_zeros: true)).to eq "$3.000"
|
121
134
|
end
|
122
135
|
end
|
123
136
|
end
|
@@ -129,7 +142,7 @@ describe Money, "formatting" do
|
|
129
142
|
it "formats Japanese currency in Japanese properly" do
|
130
143
|
money = Money.new(1000, "JPY")
|
131
144
|
expect(money.format).to eq "1,000円"
|
132
|
-
expect(money.format(:
|
145
|
+
expect(money.format(symbol: false)).to eq "1,000"
|
133
146
|
end
|
134
147
|
|
135
148
|
after { I18n.locale = @_locale }
|
@@ -144,8 +157,18 @@ describe Money, "formatting" do
|
|
144
157
|
expect(Money.new(10_00, "BHD").format).to eq "ب.د1.000"
|
145
158
|
end
|
146
159
|
|
147
|
-
|
148
|
-
|
160
|
+
context "when :subunit_to_unit is 1" do
|
161
|
+
it "does not display a decimal part" do
|
162
|
+
expect(Money.new(10_00, "VUV").format).to eq "Vt1,000"
|
163
|
+
end
|
164
|
+
|
165
|
+
it "does not displays a decimal part when infinite_precision is false" do
|
166
|
+
expect(Money.new(10_00.1, "VUV").format).to eq "Vt1,000"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "displays a decimal part when infinite_precision is true", :infinite_precision do
|
170
|
+
expect(Money.new(10_00.1, "VUV").format).to eq "Vt1,000.1"
|
171
|
+
end
|
149
172
|
end
|
150
173
|
|
151
174
|
it "respects the thousands_separator and decimal_mark defaults" do
|
@@ -186,17 +209,17 @@ describe Money, "formatting" do
|
|
186
209
|
|
187
210
|
it "inserts commas into the result if the amount is sufficiently large" do
|
188
211
|
expect(Money.us_dollar(1_000_000_000_12).format).to eq "$1,000,000,000.12"
|
189
|
-
expect(Money.us_dollar(1_000_000_000_12).format(:
|
212
|
+
expect(Money.us_dollar(1_000_000_000_12).format(no_cents: true)).to eq "$1,000,000,000"
|
190
213
|
end
|
191
214
|
|
192
215
|
it "inserts thousands separator into the result if the amount is sufficiently large and the currency symbol is at the end" do
|
193
216
|
expect(Money.euro(1_234_567_12).format).to eq "€1.234.567,12"
|
194
|
-
expect(Money.euro(1_234_567_12).format(:
|
217
|
+
expect(Money.euro(1_234_567_12).format(no_cents: true)).to eq "€1.234.567"
|
195
218
|
end
|
196
219
|
|
197
220
|
context 'when default_formatting_rules defines (display_free: true)' do
|
198
221
|
before do
|
199
|
-
Money.default_formatting_rules = { :
|
222
|
+
Money.default_formatting_rules = { display_free: "you won't pay a thing" }
|
200
223
|
end
|
201
224
|
|
202
225
|
after do
|
@@ -211,7 +234,7 @@ describe Money, "formatting" do
|
|
211
234
|
|
212
235
|
context 'with rule (display_free: false) provided' do
|
213
236
|
it 'acknowledges provided rule' do
|
214
|
-
expect(Money.new(0, 'USD').format(:
|
237
|
+
expect(Money.new(0, 'USD').format(display_free: false)).to eq '$0.00'
|
215
238
|
end
|
216
239
|
end
|
217
240
|
end
|
@@ -223,79 +246,85 @@ describe Money, "formatting" do
|
|
223
246
|
|
224
247
|
context 'acknowledges provided rule' do
|
225
248
|
it 'acknowledges provided rule' do
|
226
|
-
expect(Money.new(100, 'USD').format(:
|
249
|
+
expect(Money.new(100, 'USD').format(with_currency: true)).to eq '$1.00 USD'
|
227
250
|
end
|
228
251
|
end
|
229
252
|
end
|
230
253
|
|
231
254
|
describe ":with_currency option" do
|
232
255
|
specify "(:with_currency option => true) works as documented" do
|
233
|
-
expect(Money.ca_dollar(100).format(:
|
234
|
-
expect(Money.us_dollar(85).format(:
|
256
|
+
expect(Money.ca_dollar(100).format(with_currency: true)).to eq "$1.00 CAD"
|
257
|
+
expect(Money.us_dollar(85).format(with_currency: true)).to eq "$0.85 USD"
|
235
258
|
end
|
236
259
|
end
|
237
260
|
|
238
261
|
describe ":no_cents option" do
|
239
262
|
specify "(:with_currency option => true) works as documented" do
|
240
|
-
expect(Money.ca_dollar(100).format(:
|
241
|
-
expect(Money.ca_dollar(599).format(:
|
242
|
-
expect(Money.ca_dollar(570).format(:
|
243
|
-
expect(Money.ca_dollar(39000).format(:
|
263
|
+
expect(Money.ca_dollar(100).format(no_cents: true)).to eq "$1"
|
264
|
+
expect(Money.ca_dollar(599).format(no_cents: true)).to eq "$5"
|
265
|
+
expect(Money.ca_dollar(570).format(no_cents: true, with_currency: true)).to eq "$5 CAD"
|
266
|
+
expect(Money.ca_dollar(39000).format(no_cents: true)).to eq "$390"
|
244
267
|
end
|
245
268
|
|
246
269
|
it "respects :subunit_to_unit currency property" do
|
247
|
-
expect(Money.new(10_00, "BHD").format(:
|
270
|
+
expect(Money.new(10_00, "BHD").format(no_cents: true)).to eq "ب.د1"
|
248
271
|
end
|
249
272
|
|
250
273
|
it "inserts thousand separators if symbol contains decimal mark and no_cents is true" do
|
251
|
-
expect(Money.new(100000000, "AMD").format(:
|
252
|
-
expect(Money.new(100000000, "USD").format(:
|
253
|
-
expect(Money.new(100000000, "RUB").format(:
|
274
|
+
expect(Money.new(100000000, "AMD").format(no_cents: true)).to eq "1,000,000 դր."
|
275
|
+
expect(Money.new(100000000, "USD").format(no_cents: true)).to eq "$1,000,000"
|
276
|
+
expect(Money.new(100000000, "RUB").format(no_cents: true)).to eq "1.000.000 ₽"
|
254
277
|
end
|
255
278
|
|
256
279
|
it "doesn't incorrectly format HTML" do
|
257
280
|
money = ::Money.new(1999, "RUB")
|
258
|
-
output = money.format(:
|
281
|
+
output = money.format(html: true, no_cents: true)
|
259
282
|
expect(output).to eq "19 ₽"
|
260
283
|
end
|
284
|
+
|
285
|
+
it "doesn't incorrectly format HTML (html_wrap)" do
|
286
|
+
money = ::Money.new(1999, "RUB")
|
287
|
+
output = money.format(html_wrap: true, no_cents: true)
|
288
|
+
expect(output).to eq "<span class=\"money-whole\">19</span> <span class=\"money-currency-symbol\">₽</span>"
|
289
|
+
end
|
261
290
|
end
|
262
291
|
|
263
292
|
describe ":no_cents_if_whole option" do
|
264
|
-
specify "(:
|
265
|
-
expect(Money.new(10000, "VUV").format(:
|
266
|
-
expect(Money.new(10034, "VUV").format(:
|
267
|
-
expect(Money.new(10000, "MGA").format(:
|
268
|
-
expect(Money.new(10034, "MGA").format(:
|
269
|
-
expect(Money.new(10000, "VND").format(:
|
270
|
-
expect(Money.new(10034, "VND").format(:
|
271
|
-
expect(Money.new(10000, "USD").format(:
|
272
|
-
expect(Money.new(10034, "USD").format(:
|
273
|
-
expect(Money.new(10000, "IQD").format(:
|
274
|
-
expect(Money.new(10034, "IQD").format(:
|
275
|
-
end
|
276
|
-
|
277
|
-
specify "(:
|
278
|
-
expect(Money.new(10000, "VUV").format(:
|
279
|
-
expect(Money.new(10034, "VUV").format(:
|
280
|
-
expect(Money.new(10000, "MGA").format(:
|
281
|
-
expect(Money.new(10034, "MGA").format(:
|
282
|
-
expect(Money.new(10000, "VND").format(:
|
283
|
-
expect(Money.new(10034, "VND").format(:
|
284
|
-
expect(Money.new(10000, "USD").format(:
|
285
|
-
expect(Money.new(10034, "USD").format(:
|
286
|
-
expect(Money.new(10000, "IQD").format(:
|
287
|
-
expect(Money.new(10034, "IQD").format(:
|
293
|
+
specify "(no_cents_if_whole: true) works as documented" do
|
294
|
+
expect(Money.new(10000, "VUV").format(no_cents_if_whole: true, symbol: false)).to eq "10,000"
|
295
|
+
expect(Money.new(10034, "VUV").format(no_cents_if_whole: true, symbol: false)).to eq "10,034"
|
296
|
+
expect(Money.new(10000, "MGA").format(no_cents_if_whole: true, symbol: false)).to eq "2,000"
|
297
|
+
expect(Money.new(10034, "MGA").format(no_cents_if_whole: true, symbol: false)).to eq "2,006.8"
|
298
|
+
expect(Money.new(10000, "VND").format(no_cents_if_whole: true, symbol: false)).to eq "10.000"
|
299
|
+
expect(Money.new(10034, "VND").format(no_cents_if_whole: true, symbol: false)).to eq "10.034"
|
300
|
+
expect(Money.new(10000, "USD").format(no_cents_if_whole: true, symbol: false)).to eq "100"
|
301
|
+
expect(Money.new(10034, "USD").format(no_cents_if_whole: true, symbol: false)).to eq "100.34"
|
302
|
+
expect(Money.new(10000, "IQD").format(no_cents_if_whole: true, symbol: false)).to eq "10"
|
303
|
+
expect(Money.new(10034, "IQD").format(no_cents_if_whole: true, symbol: false)).to eq "10.034"
|
304
|
+
end
|
305
|
+
|
306
|
+
specify "(no_cents_if_whole: false) works as documented" do
|
307
|
+
expect(Money.new(10000, "VUV").format(no_cents_if_whole: false, symbol: false)).to eq "10,000"
|
308
|
+
expect(Money.new(10034, "VUV").format(no_cents_if_whole: false, symbol: false)).to eq "10,034"
|
309
|
+
expect(Money.new(10000, "MGA").format(no_cents_if_whole: false, symbol: false)).to eq "2,000.0"
|
310
|
+
expect(Money.new(10034, "MGA").format(no_cents_if_whole: false, symbol: false)).to eq "2,006.8"
|
311
|
+
expect(Money.new(10000, "VND").format(no_cents_if_whole: false, symbol: false)).to eq "10.000"
|
312
|
+
expect(Money.new(10034, "VND").format(no_cents_if_whole: false, symbol: false)).to eq "10.034"
|
313
|
+
expect(Money.new(10000, "USD").format(no_cents_if_whole: false, symbol: false)).to eq "100.00"
|
314
|
+
expect(Money.new(10034, "USD").format(no_cents_if_whole: false, symbol: false)).to eq "100.34"
|
315
|
+
expect(Money.new(10000, "IQD").format(no_cents_if_whole: false, symbol: false)).to eq "10.000"
|
316
|
+
expect(Money.new(10034, "IQD").format(no_cents_if_whole: false, symbol: false)).to eq "10.034"
|
288
317
|
end
|
289
318
|
end
|
290
319
|
|
291
320
|
describe ":symbol option" do
|
292
|
-
specify "(:
|
293
|
-
expect(Money.new(100, "GBP").format(:
|
321
|
+
specify "(symbol: a symbol string) uses the given value as the money symbol" do
|
322
|
+
expect(Money.new(100, "GBP").format(symbol: "£")).to eq "£1.00"
|
294
323
|
end
|
295
324
|
|
296
|
-
specify "(:
|
325
|
+
specify "(symbol: true) returns symbol based on the given currency code" do
|
297
326
|
one = Proc.new do |currency|
|
298
|
-
Money.new(100, currency).format(:
|
327
|
+
Money.new(100, currency).format(symbol: true)
|
299
328
|
end
|
300
329
|
|
301
330
|
# Pounds
|
@@ -324,31 +353,34 @@ describe Money, "formatting" do
|
|
324
353
|
# Brazilian Real
|
325
354
|
expect(one["BRL"]).to eq "R$1,00"
|
326
355
|
|
356
|
+
# Vietnamese Dong
|
357
|
+
expect(one["VND"]).to eq "100 ₫"
|
358
|
+
|
327
359
|
# Other
|
328
360
|
expect(one["SEK"]).to eq "1,00 kr"
|
329
361
|
expect(one["GHC"]).to eq "₵1.00"
|
330
362
|
end
|
331
363
|
|
332
|
-
specify "(:
|
364
|
+
specify "(symbol: true) returns $ when currency code is not recognized" do
|
333
365
|
currency = Money::Currency.new("EUR")
|
334
366
|
expect(currency).to receive(:symbol).and_return(nil)
|
335
|
-
expect(Money.new(100, currency).format(:
|
367
|
+
expect(Money.new(100, currency).format(symbol: true)).to eq "¤1,00"
|
336
368
|
end
|
337
369
|
|
338
|
-
specify "(:
|
339
|
-
expect(Money.new(100, "GBP").format(:
|
340
|
-
expect(Money.new(100, "EUR").format(:
|
341
|
-
expect(Money.new(100, "SEK").format(:
|
370
|
+
specify "(symbol: some non-Boolean value that evaluates to true) returns symbol based on the given currency code" do
|
371
|
+
expect(Money.new(100, "GBP").format(symbol: true)).to eq "£1.00"
|
372
|
+
expect(Money.new(100, "EUR").format(symbol: true)).to eq "€1,00"
|
373
|
+
expect(Money.new(100, "SEK").format(symbol: true)).to eq "1,00 kr"
|
342
374
|
end
|
343
375
|
|
344
|
-
specify "(:
|
376
|
+
specify "(symbol: "", nil or false) returns the amount without a symbol" do
|
345
377
|
money = Money.new(100, "GBP")
|
346
|
-
expect(money.format(:
|
347
|
-
expect(money.format(:
|
348
|
-
expect(money.format(:
|
378
|
+
expect(money.format(symbol: "")).to eq "1.00"
|
379
|
+
expect(money.format(symbol: nil)).to eq "1.00"
|
380
|
+
expect(money.format(symbol: false)).to eq "1.00"
|
349
381
|
|
350
382
|
money = Money.new(100, "JPY")
|
351
|
-
expect(money.format(:
|
383
|
+
expect(money.format(symbol: false)).to eq "100"
|
352
384
|
end
|
353
385
|
|
354
386
|
it "defaults :symbol to true" do
|
@@ -362,19 +394,19 @@ describe Money, "formatting" do
|
|
362
394
|
expect(money.format).to eq "€1,00"
|
363
395
|
end
|
364
396
|
|
365
|
-
specify "(:
|
397
|
+
specify "(symbol: false) returns a signed amount without a symbol" do
|
366
398
|
money = Money.new(-100, "EUR")
|
367
|
-
expect(money.format(:
|
399
|
+
expect(money.format(symbol: false)).to eq "-1,00"
|
368
400
|
|
369
401
|
money = Money.new(100, "EUR")
|
370
|
-
expect(money.format(:
|
371
|
-
:
|
402
|
+
expect(money.format(symbol: false,
|
403
|
+
sign_positive: true)).to eq "+1,00"
|
372
404
|
end
|
373
405
|
end
|
374
406
|
|
375
407
|
describe ":decimal_mark option" do
|
376
|
-
specify "(:
|
377
|
-
expect(Money.us_dollar(100).format(:
|
408
|
+
specify "(decimal_mark: a decimal_mark string) works as documented" do
|
409
|
+
expect(Money.us_dollar(100).format(decimal_mark: ",")).to eq "$1,00"
|
378
410
|
end
|
379
411
|
|
380
412
|
it "defaults to '.' if currency isn't recognized" do
|
@@ -383,46 +415,51 @@ describe Money, "formatting" do
|
|
383
415
|
end
|
384
416
|
|
385
417
|
describe ":separator option" do
|
386
|
-
specify "(:
|
387
|
-
expect(Money.us_dollar(100).format(:
|
418
|
+
specify "(separator: a separator string) works as documented" do
|
419
|
+
expect(Money.us_dollar(100).format(separator: ",")).to eq "$1,00"
|
388
420
|
end
|
389
421
|
end
|
390
422
|
|
391
423
|
describe ":south_asian_number_formatting delimiter" do
|
392
424
|
before(:each) do
|
393
|
-
Money::Currency.register(JSON.parse(INDIAN_BAR, :
|
425
|
+
Money::Currency.register(JSON.parse(INDIAN_BAR, symbolize_names: true))
|
394
426
|
end
|
395
427
|
|
396
428
|
after(:each) do
|
397
|
-
Money::Currency.unregister(JSON.parse(INDIAN_BAR, :
|
429
|
+
Money::Currency.unregister(JSON.parse(INDIAN_BAR, symbolize_names: true))
|
430
|
+
end
|
431
|
+
|
432
|
+
specify "(south_asian_number_formatting: true) works as documented" do
|
433
|
+
expect(Money.new(10000000, 'INR').format(south_asian_number_formatting: true, symbol: false)).to eq "1,00,000.00"
|
434
|
+
expect(Money.new(1000000000, 'INDIAN_BAR').format(south_asian_number_formatting: true, symbol: false)).to eq "1,00,000.0000"
|
435
|
+
expect(Money.new(10000000).format(south_asian_number_formatting: true)).to eq "$1,00,000.00"
|
398
436
|
end
|
399
437
|
|
400
|
-
specify "(:
|
401
|
-
expect(Money.new(10000000, 'INR').format(:
|
402
|
-
expect(Money.new(1000000000, 'INDIAN_BAR').format(:
|
403
|
-
expect(Money.new(10000000).format(:south_asian_number_formatting => true)).to eq "$1,00,000.00"
|
438
|
+
specify "(south_asian_number_formatting: true and no_cents_if_whole => true) works as documented" do
|
439
|
+
expect(Money.new(10000000, 'INR').format(south_asian_number_formatting: true, symbol: false, no_cents_if_whole: true)).to eq "1,00,000"
|
440
|
+
expect(Money.new(1000000000, 'INDIAN_BAR').format(south_asian_number_formatting: true, symbol: false, no_cents_if_whole: true)).to eq "1,00,000"
|
404
441
|
end
|
405
442
|
end
|
406
443
|
|
407
444
|
describe ":thousands_separator option" do
|
408
|
-
specify "(:
|
409
|
-
expect(Money.us_dollar(100000).format(:
|
410
|
-
expect(Money.us_dollar(200000).format(:
|
445
|
+
specify "(thousands_separator: a thousands_separator string) works as documented" do
|
446
|
+
expect(Money.us_dollar(100000).format(thousands_separator: ".")).to eq "$1.000.00"
|
447
|
+
expect(Money.us_dollar(200000).format(thousands_separator: "")).to eq "$2000.00"
|
411
448
|
end
|
412
449
|
|
413
|
-
specify "(:
|
414
|
-
expect(Money.us_dollar(100000).format(:
|
415
|
-
expect(Money.us_dollar(200000).format(:
|
450
|
+
specify "(thousands_separator: false or nil) works as documented" do
|
451
|
+
expect(Money.us_dollar(100000).format(thousands_separator: false)).to eq "$1000.00"
|
452
|
+
expect(Money.us_dollar(200000).format(thousands_separator: nil)).to eq "$2000.00"
|
416
453
|
end
|
417
454
|
|
418
|
-
specify "(:
|
419
|
-
expect(Money.us_dollar(100000).format(:
|
420
|
-
expect(Money.us_dollar(200000).format(:
|
455
|
+
specify "(delimiter: a delimiter string) works as documented" do
|
456
|
+
expect(Money.us_dollar(100000).format(delimiter: ".")).to eq "$1.000.00"
|
457
|
+
expect(Money.us_dollar(200000).format(delimiter: "")).to eq "$2000.00"
|
421
458
|
end
|
422
459
|
|
423
|
-
specify "(:
|
424
|
-
expect(Money.us_dollar(100000).format(:
|
425
|
-
expect(Money.us_dollar(200000).format(:
|
460
|
+
specify "(delimiter: false or nil) works as documented" do
|
461
|
+
expect(Money.us_dollar(100000).format(delimiter: false)).to eq "$1000.00"
|
462
|
+
expect(Money.us_dollar(200000).format(delimiter: nil)).to eq "$2000.00"
|
426
463
|
end
|
427
464
|
|
428
465
|
it "defaults to ',' if currency isn't recognized" do
|
@@ -433,11 +470,11 @@ describe Money, "formatting" do
|
|
433
470
|
before { Money.use_i18n = false }
|
434
471
|
|
435
472
|
it "should respect explicit overriding of thousands_separator/delimiter when decimal_mark/separator collide and there’s no decimal component for currencies that have no subunit" do
|
436
|
-
expect(Money.new(300_000, 'ISK').format(:
|
473
|
+
expect(Money.new(300_000, 'ISK').format(thousands_separator: ",", decimal_mark: '.')).to eq "kr300,000"
|
437
474
|
end
|
438
475
|
|
439
476
|
it "should respect explicit overriding of thousands_separator/delimiter when decimal_mark/separator collide and there’s no decimal component for currencies with subunits that drop_trailing_zeros" do
|
440
|
-
expect(Money.new(300_000, 'USD').format(:
|
477
|
+
expect(Money.new(300_000, 'USD').format(thousands_separator: ".", decimal_mark: ',', drop_trailing_zeros: true)).to eq "$3.000"
|
441
478
|
end
|
442
479
|
|
443
480
|
after { Money.use_i18n = true}
|
@@ -445,131 +482,148 @@ describe Money, "formatting" do
|
|
445
482
|
end
|
446
483
|
|
447
484
|
describe ":thousands_separator and :decimal_mark option" do
|
448
|
-
specify "(:
|
485
|
+
specify "(thousands_separator: a thousands_separator string, decimal_mark: a decimal_mark string) works as documented" do
|
449
486
|
expect(Money.new(123_456_789, "USD").format(thousands_separator: ".", decimal_mark: ",")).to eq("$1.234.567,89")
|
450
487
|
expect(Money.new(987_654_321, "USD").format(thousands_separator: " ", decimal_mark: ".")).to eq("$9 876 543.21")
|
451
488
|
end
|
452
489
|
end
|
453
490
|
|
454
491
|
describe ":html option" do
|
455
|
-
specify "(:
|
456
|
-
string = Money.ca_dollar(570).format(:
|
492
|
+
specify "(html: true) works as documented" do
|
493
|
+
string = Money.ca_dollar(570).format(html: true, with_currency: true)
|
457
494
|
expect(string).to eq "$5.70 <span class=\"currency\">CAD</span>"
|
458
495
|
end
|
459
496
|
|
460
497
|
specify "should fallback to symbol if entity is not available" do
|
461
|
-
string = Money.new(570, 'DKK').format(:
|
498
|
+
string = Money.new(570, 'DKK').format(html: true)
|
462
499
|
expect(string).to eq "5,70 kr."
|
463
500
|
end
|
464
501
|
end
|
465
502
|
|
466
503
|
describe ":html_wrap_symbol option" do
|
467
|
-
specify "(:
|
468
|
-
string = Money.ca_dollar(570).format(:
|
504
|
+
specify "(html_wrap_symbol: true) works as documented" do
|
505
|
+
string = Money.ca_dollar(570).format(html_wrap_symbol: true)
|
469
506
|
expect(string).to eq "<span class=\"currency_symbol\">$</span>5.70"
|
470
507
|
end
|
471
508
|
end
|
472
509
|
|
510
|
+
describe ":html_wrap option" do
|
511
|
+
specify "(html_wrap: true) works as documented" do
|
512
|
+
string = Money.ca_dollar(570).format(html_wrap: true)
|
513
|
+
expect(string).to eq "<span class=\"money-currency-symbol\">$</span><span class=\"money-whole\">5</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">70</span>"
|
514
|
+
end
|
515
|
+
|
516
|
+
specify "(html_wrap: true, with_currency: true)" do
|
517
|
+
string = Money.ca_dollar(570).format(html_wrap: true, with_currency: true)
|
518
|
+
expect(string).to eq "<span class=\"money-currency-symbol\">$</span><span class=\"money-whole\">5</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">70</span> <span class=\"money-currency\">CAD</span>"
|
519
|
+
end
|
520
|
+
|
521
|
+
specify "should fallback to symbol if entity is not available" do
|
522
|
+
string = Money.new(570, 'DKK').format(html_wrap: true)
|
523
|
+
expect(string).to eq "<span class=\"money-whole\">5</span><span class=\"money-decimal-mark\">,</span><span class=\"money-decimal\">70</span> <span class=\"money-currency-symbol\">kr.</span>"
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
473
527
|
describe ":symbol_position option" do
|
474
528
|
it "inserts currency symbol before the amount when set to :before" do
|
475
|
-
expect(Money.euro(1_234_567_12).format(:
|
529
|
+
expect(Money.euro(1_234_567_12).format(symbol_position: :before)).to eq "€1.234.567,12"
|
476
530
|
end
|
477
531
|
|
478
532
|
it "inserts currency symbol after the amount when set to :after" do
|
479
|
-
expect(Money.us_dollar(1_000_000_000_12).format(:
|
533
|
+
expect(Money.us_dollar(1_000_000_000_12).format(symbol_position: :after)).to eq "1,000,000,000.12 $"
|
480
534
|
end
|
481
535
|
|
482
536
|
it "raises an ArgumentError when passed an invalid option" do
|
483
|
-
expect{Money.euro(0).format(:
|
537
|
+
expect{Money.euro(0).format(symbol_position: :befor)}.to raise_error(ArgumentError)
|
484
538
|
end
|
485
539
|
end
|
486
540
|
|
487
541
|
describe ":sign_before_symbol option" do
|
488
|
-
specify "(:
|
489
|
-
expect(Money.us_dollar(-100000).format(:
|
542
|
+
specify "(sign_before_symbol: true) works as documented" do
|
543
|
+
expect(Money.us_dollar(-100000).format(sign_before_symbol: true)).to eq "-$1,000.00"
|
490
544
|
end
|
491
545
|
|
492
|
-
specify "(:
|
493
|
-
expect(Money.us_dollar(-100000).format(:
|
494
|
-
expect(Money.us_dollar(-100000).format(:
|
546
|
+
specify "(sign_before_symbol: false) works as documented" do
|
547
|
+
expect(Money.us_dollar(-100000).format(sign_before_symbol: false)).to eq "$-1,000.00"
|
548
|
+
expect(Money.us_dollar(-100000).format(sign_before_symbol: nil)).to eq "$-1,000.00"
|
495
549
|
end
|
496
550
|
end
|
497
551
|
|
498
552
|
describe ":symbol_before_without_space option" do
|
499
553
|
it "does not insert space between currency symbol and amount when set to true" do
|
500
|
-
expect(Money.euro(1_234_567_12).format(:
|
554
|
+
expect(Money.euro(1_234_567_12).format(symbol_position: :before, symbol_before_without_space: true)).to eq "€1.234.567,12"
|
501
555
|
end
|
502
556
|
|
503
557
|
it "inserts space between currency symbol and amount when set to false" do
|
504
|
-
expect(Money.euro(1_234_567_12).format(:
|
558
|
+
expect(Money.euro(1_234_567_12).format(symbol_position: :before, symbol_before_without_space: false)).to eq "€ 1.234.567,12"
|
505
559
|
end
|
506
560
|
|
507
561
|
it "defaults to true" do
|
508
|
-
expect(Money.euro(1_234_567_12).format(:
|
562
|
+
expect(Money.euro(1_234_567_12).format(symbol_position: :before)).to eq "€1.234.567,12"
|
509
563
|
end
|
510
564
|
end
|
511
565
|
|
512
566
|
describe ":symbol_after_without_space option" do
|
513
567
|
it "does not insert space between amount and currency symbol when set to true" do
|
514
|
-
expect(Money.euro(1_234_567_12).format(:
|
568
|
+
expect(Money.euro(1_234_567_12).format(symbol_position: :after, symbol_after_without_space: true)).to eq "1.234.567,12€"
|
515
569
|
end
|
516
570
|
|
517
571
|
it "inserts space between amount and currency symbol when set to false" do
|
518
|
-
expect(Money.euro(1_234_567_12).format(:
|
572
|
+
expect(Money.euro(1_234_567_12).format(symbol_position: :after, symbol_after_without_space: false)).to eq "1.234.567,12 €"
|
519
573
|
end
|
520
574
|
|
521
575
|
it "defaults to false" do
|
522
|
-
expect(Money.euro(1_234_567_12).format(:
|
576
|
+
expect(Money.euro(1_234_567_12).format(symbol_position: :after)).to eq "1.234.567,12 €"
|
523
577
|
end
|
524
578
|
end
|
525
579
|
|
526
580
|
describe ":sign_positive option" do
|
527
|
-
specify "(:
|
528
|
-
expect(Money.us_dollar( 0).format(:
|
529
|
-
expect(Money.us_dollar( 100000).format(:
|
530
|
-
expect(Money.us_dollar(-100000).format(:
|
581
|
+
specify "(sign_positive: true, sign_before_symbol: true) works as documented" do
|
582
|
+
expect(Money.us_dollar( 0).format(sign_positive: true, sign_before_symbol: true)).to eq "$0.00"
|
583
|
+
expect(Money.us_dollar( 100000).format(sign_positive: true, sign_before_symbol: true)).to eq "+$1,000.00"
|
584
|
+
expect(Money.us_dollar(-100000).format(sign_positive: true, sign_before_symbol: true)).to eq "-$1,000.00"
|
531
585
|
end
|
532
586
|
|
533
|
-
specify "(:
|
534
|
-
expect(Money.us_dollar( 0).format(:
|
535
|
-
expect(Money.us_dollar( 100000).format(:
|
536
|
-
expect(Money.us_dollar( 100000).format(:
|
537
|
-
expect(Money.us_dollar(-100000).format(:
|
538
|
-
expect(Money.us_dollar(-100000).format(:
|
587
|
+
specify "(sign_positive: true, sign_before_symbol: false) works as documented" do
|
588
|
+
expect(Money.us_dollar( 0).format(sign_positive: true, sign_before_symbol: false)).to eq "$0.00"
|
589
|
+
expect(Money.us_dollar( 100000).format(sign_positive: true, sign_before_symbol: false)).to eq "$+1,000.00"
|
590
|
+
expect(Money.us_dollar( 100000).format(sign_positive: true, sign_before_symbol: nil)).to eq "$+1,000.00"
|
591
|
+
expect(Money.us_dollar(-100000).format(sign_positive: true, sign_before_symbol: false)).to eq "$-1,000.00"
|
592
|
+
expect(Money.us_dollar(-100000).format(sign_positive: true, sign_before_symbol: nil)).to eq "$-1,000.00"
|
539
593
|
end
|
540
594
|
|
541
|
-
specify "(:
|
542
|
-
expect(Money.us_dollar( 100000).format(:
|
543
|
-
expect(Money.us_dollar(-100000).format(:
|
595
|
+
specify "(sign_positive: false, sign_before_symbol: true) works as documented" do
|
596
|
+
expect(Money.us_dollar( 100000).format(sign_positive: false, sign_before_symbol: true)).to eq "$1,000.00"
|
597
|
+
expect(Money.us_dollar(-100000).format(sign_positive: false, sign_before_symbol: true)).to eq "-$1,000.00"
|
544
598
|
end
|
545
599
|
|
546
|
-
specify "(:
|
547
|
-
expect(Money.us_dollar( 100000).format(:
|
548
|
-
expect(Money.us_dollar( 100000).format(:
|
549
|
-
expect(Money.us_dollar(-100000).format(:
|
550
|
-
expect(Money.us_dollar(-100000).format(:
|
600
|
+
specify "(sign_positive: false, sign_before_symbol: false) works as documented" do
|
601
|
+
expect(Money.us_dollar( 100000).format(sign_positive: false, sign_before_symbol: false)).to eq "$1,000.00"
|
602
|
+
expect(Money.us_dollar( 100000).format(sign_positive: false, sign_before_symbol: nil)).to eq "$1,000.00"
|
603
|
+
expect(Money.us_dollar(-100000).format(sign_positive: false, sign_before_symbol: false)).to eq "$-1,000.00"
|
604
|
+
expect(Money.us_dollar(-100000).format(sign_positive: false, sign_before_symbol: nil)).to eq "$-1,000.00"
|
551
605
|
end
|
552
606
|
end
|
553
607
|
|
554
608
|
describe ":rounded_infinite_precision option", :infinite_precision do
|
555
609
|
it "does round fractional when set to true" do
|
556
|
-
expect(Money.new(BigDecimal
|
557
|
-
expect(Money.new(BigDecimal
|
558
|
-
expect(Money.new(BigDecimal
|
559
|
-
expect(Money.new(BigDecimal
|
560
|
-
expect(Money.new(BigDecimal
|
561
|
-
expect(Money.new(BigDecimal
|
562
|
-
expect(Money.new(BigDecimal
|
610
|
+
expect(Money.new(BigDecimal('12.1'), "USD").format(rounded_infinite_precision: true)).to eq "$0.12"
|
611
|
+
expect(Money.new(BigDecimal('12.5'), "USD").format(rounded_infinite_precision: true)).to eq "$0.13"
|
612
|
+
expect(Money.new(BigDecimal('123.1'), "BHD").format(rounded_infinite_precision: true)).to eq "ب.د0.123"
|
613
|
+
expect(Money.new(BigDecimal('123.5'), "BHD").format(rounded_infinite_precision: true)).to eq "ب.د0.124"
|
614
|
+
expect(Money.new(BigDecimal('100.1'), "USD").format(rounded_infinite_precision: true)).to eq "$1.00"
|
615
|
+
expect(Money.new(BigDecimal('109.5'), "USD").format(rounded_infinite_precision: true)).to eq "$1.10"
|
616
|
+
expect(Money.new(BigDecimal('1.7'), "MGA").format(rounded_infinite_precision: true)).to eq "Ar0.4"
|
563
617
|
end
|
564
618
|
|
565
619
|
it "does not round fractional when set to false" do
|
566
|
-
expect(Money.new(BigDecimal
|
567
|
-
expect(Money.new(BigDecimal
|
568
|
-
expect(Money.new(BigDecimal
|
569
|
-
expect(Money.new(BigDecimal
|
570
|
-
expect(Money.new(BigDecimal
|
571
|
-
expect(Money.new(BigDecimal
|
572
|
-
expect(Money.new(BigDecimal
|
620
|
+
expect(Money.new(BigDecimal('12.1'), "USD").format(rounded_infinite_precision: false)).to eq "$0.121"
|
621
|
+
expect(Money.new(BigDecimal('12.5'), "USD").format(rounded_infinite_precision: false)).to eq "$0.125"
|
622
|
+
expect(Money.new(BigDecimal('123.1'), "BHD").format(rounded_infinite_precision: false)).to eq "ب.د0.1231"
|
623
|
+
expect(Money.new(BigDecimal('123.5'), "BHD").format(rounded_infinite_precision: false)).to eq "ب.د0.1235"
|
624
|
+
expect(Money.new(BigDecimal('100.1'), "USD").format(rounded_infinite_precision: false)).to eq "$1.001"
|
625
|
+
expect(Money.new(BigDecimal('109.5'), "USD").format(rounded_infinite_precision: false)).to eq "$1.095"
|
626
|
+
expect(Money.new(BigDecimal('1.7'), "MGA").format(rounded_infinite_precision: false)).to eq "Ar0.34"
|
573
627
|
end
|
574
628
|
|
575
629
|
describe "with i18n = false" do
|
@@ -582,13 +636,13 @@ describe Money, "formatting" do
|
|
582
636
|
end
|
583
637
|
|
584
638
|
it 'does round fractional when set to true' do
|
585
|
-
expect(Money.new(BigDecimal
|
586
|
-
expect(Money.new(BigDecimal
|
587
|
-
expect(Money.new(BigDecimal
|
588
|
-
expect(Money.new(BigDecimal
|
639
|
+
expect(Money.new(BigDecimal('12.1'), "EUR").format(rounded_infinite_precision: true)).to eq "€0,12"
|
640
|
+
expect(Money.new(BigDecimal('12.5'), "EUR").format(rounded_infinite_precision: true)).to eq "€0,13"
|
641
|
+
expect(Money.new(BigDecimal('100.1'), "EUR").format(rounded_infinite_precision: true)).to eq "€1,00"
|
642
|
+
expect(Money.new(BigDecimal('109.5'), "EUR").format(rounded_infinite_precision: true)).to eq "€1,10"
|
589
643
|
|
590
|
-
expect(Money.new(BigDecimal
|
591
|
-
expect(Money.new(BigDecimal
|
644
|
+
expect(Money.new(BigDecimal('100012.1'), "EUR").format(rounded_infinite_precision: true)).to eq "€1.000,12"
|
645
|
+
expect(Money.new(BigDecimal('100012.5'), "EUR").format(rounded_infinite_precision: true)).to eq "€1.000,13"
|
592
646
|
end
|
593
647
|
end
|
594
648
|
|
@@ -599,7 +653,7 @@ describe Money, "formatting" do
|
|
599
653
|
I18n.locale = :de
|
600
654
|
I18n.backend.store_translations(
|
601
655
|
:de,
|
602
|
-
:
|
656
|
+
number: { currency: { format: { delimiter: ".", separator: "," } } }
|
603
657
|
)
|
604
658
|
end
|
605
659
|
|
@@ -609,45 +663,81 @@ describe Money, "formatting" do
|
|
609
663
|
end
|
610
664
|
|
611
665
|
it 'does round fractional when set to true' do
|
612
|
-
expect(Money.new(BigDecimal
|
613
|
-
expect(Money.new(BigDecimal
|
614
|
-
expect(Money.new(BigDecimal
|
615
|
-
expect(Money.new(BigDecimal
|
616
|
-
expect(Money.new(BigDecimal
|
617
|
-
expect(Money.new(BigDecimal
|
618
|
-
expect(Money.new(BigDecimal
|
666
|
+
expect(Money.new(BigDecimal('12.1'), "USD").format(rounded_infinite_precision: true)).to eq "$0,12"
|
667
|
+
expect(Money.new(BigDecimal('12.5'), "USD").format(rounded_infinite_precision: true)).to eq "$0,13"
|
668
|
+
expect(Money.new(BigDecimal('123.1'), "BHD").format(rounded_infinite_precision: true)).to eq "ب.د0,123"
|
669
|
+
expect(Money.new(BigDecimal('123.5'), "BHD").format(rounded_infinite_precision: true)).to eq "ب.د0,124"
|
670
|
+
expect(Money.new(BigDecimal('100.1'), "USD").format(rounded_infinite_precision: true)).to eq "$1,00"
|
671
|
+
expect(Money.new(BigDecimal('109.5'), "USD").format(rounded_infinite_precision: true)).to eq "$1,10"
|
672
|
+
expect(Money.new(BigDecimal('1'), "MGA").format(rounded_infinite_precision: true)).to eq "Ar0,2"
|
619
673
|
end
|
620
674
|
end
|
621
675
|
end
|
622
676
|
|
677
|
+
describe ':format option' do
|
678
|
+
let(:money) { Money.new(99_99, 'USD') }
|
679
|
+
|
680
|
+
it 'uses provided format as a template' do
|
681
|
+
expect(money.format(format: '%n')).to eq('99.99')
|
682
|
+
expect(money.format(format: '%u')).to eq('$')
|
683
|
+
expect(money.format(format: '%u%n')).to eq('$99.99')
|
684
|
+
expect(money.format(format: '%n%u')).to eq('99.99$')
|
685
|
+
expect(money.format(format: '%u %n')).to eq('$ 99.99')
|
686
|
+
expect(money.format(format: 'Your balance is: %u%n')).to eq('Your balance is: $99.99')
|
687
|
+
end
|
688
|
+
|
689
|
+
it 'ignores :symbol_position in favour of format' do
|
690
|
+
expect(money.format(format: '%u%n', symbol_position: :after)).to eq('$99.99')
|
691
|
+
expect(money.format(format: '%n%u', symbol_position: :before)).to eq('99.99$')
|
692
|
+
end
|
693
|
+
|
694
|
+
it 'ignores :symbol_before_without_space in favour of format' do
|
695
|
+
expect(money.format(format: '%u %n', symbol_position: :before, symbol_before_without_space: true)).to eq('$ 99.99')
|
696
|
+
expect(money.format(format: '%u%n', symbol_position: :before, symbol_before_without_space: false)).to eq('$99.99')
|
697
|
+
end
|
698
|
+
|
699
|
+
it 'ignores :symbol_after_without_space in favour of format' do
|
700
|
+
expect(money.format(format: '%n %u', symbol_position: :after, symbol_after_without_space: true)).to eq('99.99 $')
|
701
|
+
expect(money.format(format: '%n%u', symbol_position: :after, symbol_after_without_space: false)).to eq('99.99$')
|
702
|
+
end
|
703
|
+
|
704
|
+
it 'works with sign' do
|
705
|
+
money = Money.new(-99_99, 'USD')
|
706
|
+
|
707
|
+
expect(money.format(format: '%n%u', sign_before_symbol: false)).to eq('-99.99$')
|
708
|
+
expect(money.format(format: '%u%n', sign_before_symbol: false)).to eq('$-99.99')
|
709
|
+
expect(money.format(format: '%u%n', sign_before_symbol: true)).to eq('-$99.99')
|
710
|
+
end
|
711
|
+
end
|
712
|
+
|
623
713
|
context "when the monetary value is 0" do
|
624
714
|
let(:money) { Money.us_dollar(0) }
|
625
715
|
|
626
716
|
it "returns 'free' when :display_free is true" do
|
627
|
-
expect(money.format(:
|
717
|
+
expect(money.format(display_free: true)).to eq 'free'
|
628
718
|
end
|
629
719
|
|
630
720
|
it "returns '$0.00' when :display_free is false or not given" do
|
631
721
|
expect(money.format).to eq '$0.00'
|
632
|
-
expect(money.format(:
|
633
|
-
expect(money.format(:
|
722
|
+
expect(money.format(display_free: false)).to eq '$0.00'
|
723
|
+
expect(money.format(display_free: nil)).to eq '$0.00'
|
634
724
|
end
|
635
725
|
|
636
726
|
it "returns the value specified by :display_free if it's a string-like object" do
|
637
|
-
expect(money.format(:
|
727
|
+
expect(money.format(display_free: 'gratis')).to eq 'gratis'
|
638
728
|
end
|
639
729
|
end
|
640
730
|
end
|
641
731
|
|
642
732
|
context "custom currencies with 4 decimal places" do
|
643
733
|
before :each do
|
644
|
-
Money::Currency.register(JSON.parse(BAR, :
|
645
|
-
Money::Currency.register(JSON.parse(EU4, :
|
734
|
+
Money::Currency.register(JSON.parse(BAR, symbolize_names: true))
|
735
|
+
Money::Currency.register(JSON.parse(EU4, symbolize_names: true))
|
646
736
|
end
|
647
737
|
|
648
738
|
after :each do
|
649
|
-
Money::Currency.unregister(JSON.parse(BAR, :
|
650
|
-
Money::Currency.unregister(JSON.parse(EU4, :
|
739
|
+
Money::Currency.unregister(JSON.parse(BAR, symbolize_names: true))
|
740
|
+
Money::Currency.unregister(JSON.parse(EU4, symbolize_names: true))
|
651
741
|
end
|
652
742
|
|
653
743
|
it "respects custom subunit to unit, decimal and thousands separator" do
|
@@ -689,6 +779,7 @@ describe Money, "formatting" do
|
|
689
779
|
expect(Money.new(1999_98, "DKK").format).to eq("1.999,98 kr.")
|
690
780
|
expect(Money.new(1999_98, "NOK").format).to eq("1.999,98 kr")
|
691
781
|
expect(Money.new(1999_98, "SEK").format).to eq("1 999,98 kr")
|
782
|
+
expect(Money.new(1999_98, "BCH").format).to eq("0.00199998 ₿")
|
692
783
|
end
|
693
784
|
|
694
785
|
it "returns ambiguous signs when disambiguate is false" do
|
@@ -697,6 +788,7 @@ describe Money, "formatting" do
|
|
697
788
|
expect(Money.new(1999_98, "DKK").format(disambiguate: false)).to eq("1.999,98 kr.")
|
698
789
|
expect(Money.new(1999_98, "NOK").format(disambiguate: false)).to eq("1.999,98 kr")
|
699
790
|
expect(Money.new(1999_98, "SEK").format(disambiguate: false)).to eq("1 999,98 kr")
|
791
|
+
expect(Money.new(1999_98, "BCH").format(disambiguate: false)).to eq("0.00199998 ₿")
|
700
792
|
end
|
701
793
|
|
702
794
|
it "returns disambiguate signs when disambiguate: true" do
|
@@ -705,6 +797,25 @@ describe Money, "formatting" do
|
|
705
797
|
expect(Money.new(1999_98, "DKK").format(disambiguate: true)).to eq("1.999,98 DKK")
|
706
798
|
expect(Money.new(1999_98, "NOK").format(disambiguate: true)).to eq("1.999,98 NOK")
|
707
799
|
expect(Money.new(1999_98, "SEK").format(disambiguate: true)).to eq("1 999,98 SEK")
|
800
|
+
expect(Money.new(1999_98, "BCH").format(disambiguate: true)).to eq("0.00199998 ₿CH")
|
801
|
+
end
|
802
|
+
|
803
|
+
it "returns disambiguate signs when disambiguate: true and symbol: true" do
|
804
|
+
expect(Money.new(1999_98, "USD").format(disambiguate: true, symbol: true)).to eq("US$1,999.98")
|
805
|
+
expect(Money.new(1999_98, "CAD").format(disambiguate: true, symbol: true)).to eq("C$1,999.98")
|
806
|
+
expect(Money.new(1999_98, "DKK").format(disambiguate: true, symbol: true)).to eq("1.999,98 DKK")
|
807
|
+
expect(Money.new(1999_98, "NOK").format(disambiguate: true, symbol: true)).to eq("1.999,98 NOK")
|
808
|
+
expect(Money.new(1999_98, "SEK").format(disambiguate: true, symbol: true)).to eq("1 999,98 SEK")
|
809
|
+
expect(Money.new(1999_98, "BCH").format(disambiguate: true, symbol: true)).to eq("0.00199998 ₿CH")
|
810
|
+
end
|
811
|
+
|
812
|
+
it "returns no signs when disambiguate: true and symbol: false" do
|
813
|
+
expect(Money.new(1999_98, "USD").format(disambiguate: true, symbol: false)).to eq("1,999.98")
|
814
|
+
expect(Money.new(1999_98, "CAD").format(disambiguate: true, symbol: false)).to eq("1,999.98")
|
815
|
+
expect(Money.new(1999_98, "DKK").format(disambiguate: true, symbol: false)).to eq("1.999,98")
|
816
|
+
expect(Money.new(1999_98, "NOK").format(disambiguate: true, symbol: false)).to eq("1.999,98")
|
817
|
+
expect(Money.new(1999_98, "SEK").format(disambiguate: true, symbol: false)).to eq("1 999,98")
|
818
|
+
expect(Money.new(1999_98, "BCH").format(disambiguate: true, symbol: false)).to eq("0.00199998")
|
708
819
|
end
|
709
820
|
|
710
821
|
it "should never return an ambiguous format with disambiguate: true" do
|
@@ -720,18 +831,24 @@ describe Money, "formatting" do
|
|
720
831
|
end
|
721
832
|
|
722
833
|
describe ":drop_trailing_zeros option" do
|
723
|
-
specify "(:
|
724
|
-
expect(Money.new(89000, "BTC").format(:
|
725
|
-
expect(Money.new(
|
726
|
-
expect(Money.new(
|
727
|
-
expect(Money.new(
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
expect(Money.new(
|
834
|
+
specify "(drop_trailing_zeros: true) works as documented" do
|
835
|
+
expect(Money.new(89000, "BTC").format(drop_trailing_zeros: true, symbol: false)).to eq "0.00089"
|
836
|
+
expect(Money.new(89000, "BCH").format(drop_trailing_zeros: true, symbol: false)).to eq "0.00089"
|
837
|
+
expect(Money.new(100089000, "BTC").format(drop_trailing_zeros: true, symbol: false)).to eq "1.00089"
|
838
|
+
expect(Money.new(100089000, "BCH").format(drop_trailing_zeros: true, symbol: false)).to eq "1.00089"
|
839
|
+
expect(Money.new(100000000, "BTC").format(drop_trailing_zeros: true, symbol: false)).to eq "1"
|
840
|
+
expect(Money.new(100000000, "BCH").format(drop_trailing_zeros: true, symbol: false)).to eq "1"
|
841
|
+
expect(Money.new(110, "AUD").format(drop_trailing_zeros: true, symbol: false)).to eq "1.1"
|
842
|
+
end
|
843
|
+
|
844
|
+
specify "(drop_trailing_zeros: false) works as documented" do
|
845
|
+
expect(Money.new(89000, "BTC").format(drop_trailing_zeros: false, symbol: false)).to eq "0.00089000"
|
846
|
+
expect(Money.new(89000, "BCH").format(drop_trailing_zeros: false, symbol: false)).to eq "0.00089000"
|
847
|
+
expect(Money.new(100089000, "BTC").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00089000"
|
848
|
+
expect(Money.new(100089000, "BCH").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00089000"
|
849
|
+
expect(Money.new(100000000, "BTC").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00000000"
|
850
|
+
expect(Money.new(100000000, "BCH").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00000000"
|
851
|
+
expect(Money.new(110, "AUD").format(drop_trailing_zeros: false, symbol: false)).to eq "1.10"
|
735
852
|
end
|
736
853
|
end
|
737
854
|
end
|