money 4.0.1 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +405 -391
- data/LICENSE +21 -21
- data/README.md +249 -243
- data/Rakefile +52 -49
- data/config/currency.json +2068 -2068
- data/config/currency_bc.json +41 -41
- data/lib/money.rb +28 -28
- data/lib/money/bank/base.rb +130 -131
- data/lib/money/bank/variable_exchange.rb +253 -252
- data/lib/money/core_extensions.rb +82 -82
- data/lib/money/currency.rb +280 -263
- data/lib/money/currency_loader.rb +21 -19
- data/lib/money/money.rb +411 -405
- data/lib/money/money/arithmetic.rb +257 -246
- data/lib/money/money/formatting.rb +251 -260
- data/lib/money/money/parsing.rb +350 -350
- data/money.gemspec +29 -29
- data/spec/bank/base_spec.rb +69 -72
- data/spec/bank/variable_exchange_spec.rb +233 -238
- data/spec/core_extensions_spec.rb +160 -158
- data/spec/currency_spec.rb +139 -120
- data/spec/money/arithmetic_spec.rb +482 -479
- data/spec/money/formatting_spec.rb +402 -383
- data/spec/money/parsing_spec.rb +210 -197
- data/spec/money_spec.rb +312 -292
- data/spec/spec_helper.rb +32 -28
- metadata +14 -14
@@ -1,383 +1,402 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe Money do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
("
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
("
|
32
|
-
|
33
|
-
|
34
|
-
("
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
"
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
I18n.locale =
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
it "
|
142
|
-
Money.
|
143
|
-
Money.
|
144
|
-
end
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
Money.
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
Money.new(100,
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
end
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Money, "formatting" do
|
6
|
+
|
7
|
+
context "without i18n" do
|
8
|
+
subject { Money.empty("USD") }
|
9
|
+
|
10
|
+
its(:thousands_separator) { should == "," }
|
11
|
+
its(:decimal_mark) { should == "." }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "with i18n but use_i18n = false" do
|
15
|
+
before :each do
|
16
|
+
reset_i18n
|
17
|
+
I18n.locale = :de
|
18
|
+
I18n.backend.store_translations(
|
19
|
+
:de,
|
20
|
+
:number => { :currency => { :format => { :delimiter => ".", :separator => "," } } }
|
21
|
+
)
|
22
|
+
Money.use_i18n = false
|
23
|
+
end
|
24
|
+
|
25
|
+
after :each do
|
26
|
+
reset_i18n
|
27
|
+
I18n.locale = :en
|
28
|
+
Money.use_i18n = true
|
29
|
+
end
|
30
|
+
|
31
|
+
subject { Money.empty("USD") }
|
32
|
+
|
33
|
+
its(:thousands_separator) { should == "," }
|
34
|
+
its(:decimal_mark) { should == "." }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with i18n" do
|
38
|
+
after :each do
|
39
|
+
reset_i18n
|
40
|
+
I18n.locale = :en
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with number.format.*" do
|
44
|
+
before :each do
|
45
|
+
reset_i18n
|
46
|
+
I18n.locale = :de
|
47
|
+
I18n.backend.store_translations(
|
48
|
+
:de,
|
49
|
+
:number => { :format => { :delimiter => ".", :separator => "," } }
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
subject { Money.empty("USD") }
|
54
|
+
|
55
|
+
its(:thousands_separator) { should == "." }
|
56
|
+
its(:decimal_mark) { should == "," }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with number.currency.format.*" do
|
60
|
+
before :each do
|
61
|
+
reset_i18n
|
62
|
+
I18n.locale = :de
|
63
|
+
I18n.backend.store_translations(
|
64
|
+
:de,
|
65
|
+
:number => { :currency => { :format => { :delimiter => ".", :separator => "," } } }
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
subject { Money.empty("USD") }
|
70
|
+
|
71
|
+
its(:thousands_separator) { should == "." }
|
72
|
+
its(:decimal_mark) { should == "," }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#format" do
|
77
|
+
context "Locale :ja" do
|
78
|
+
before { @_locale = I18n.locale; I18n.locale = :ja }
|
79
|
+
|
80
|
+
it "formats Japanese currency in Japanese properly" do
|
81
|
+
Money.new(1000, "JPY").format.should == "1,000円"
|
82
|
+
end
|
83
|
+
|
84
|
+
after { I18n.locale = @_locale }
|
85
|
+
end
|
86
|
+
|
87
|
+
it "returns the monetary value as a string" do
|
88
|
+
Money.ca_dollar(100).format.should == "$1.00"
|
89
|
+
Money.new(40008).format.should == "$400.08"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "respects :subunit_to_unit currency property" do
|
93
|
+
Money.new(10_00, "BHD").format.should == "ب.د1.000"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "does not display a decimal when :subunit_to_unit is 1" do
|
97
|
+
Money.new(10_00, "CLP").format.should == "$1.000"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "respects the thousands_separator and decimal_mark defaults" do
|
101
|
+
one_thousand = Proc.new do |currency|
|
102
|
+
Money.new(1000_00, currency).format
|
103
|
+
end
|
104
|
+
|
105
|
+
# Pounds
|
106
|
+
one_thousand["GBP"].should == "£1,000.00"
|
107
|
+
|
108
|
+
# Dollars
|
109
|
+
one_thousand["USD"].should == "$1,000.00"
|
110
|
+
one_thousand["CAD"].should == "$1,000.00"
|
111
|
+
one_thousand["AUD"].should == "$1,000.00"
|
112
|
+
one_thousand["NZD"].should == "$1,000.00"
|
113
|
+
one_thousand["ZWD"].should == "$1,000.00"
|
114
|
+
|
115
|
+
# Yen
|
116
|
+
one_thousand["JPY"].should == "¥100,000"
|
117
|
+
one_thousand["CNY"].should == "¥1,000.00"
|
118
|
+
|
119
|
+
# Euro
|
120
|
+
one_thousand["EUR"].should == "1.000,00 €"
|
121
|
+
|
122
|
+
# Rupees
|
123
|
+
one_thousand["INR"].should == "₨1,000.00"
|
124
|
+
one_thousand["NPR"].should == "₨1,000.00"
|
125
|
+
one_thousand["SCR"].should == "1,000.00 ₨"
|
126
|
+
one_thousand["LKR"].should == "1,000.00 ₨"
|
127
|
+
|
128
|
+
# Brazilian Real
|
129
|
+
one_thousand["BRL"].should == "R$ 1.000,00"
|
130
|
+
|
131
|
+
# Other
|
132
|
+
one_thousand["SEK"].should == "kr1,000.00"
|
133
|
+
one_thousand["GHC"].should == "₵1,000.00"
|
134
|
+
end
|
135
|
+
|
136
|
+
it "inserts commas into the result if the amount is sufficiently large" do
|
137
|
+
Money.us_dollar(1_000_000_000_12).format.should == "$1,000,000,000.12"
|
138
|
+
Money.us_dollar(1_000_000_000_12).format(:no_cents => true).should == "$1,000,000,000"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "inserts thousands separator into the result if the amount is sufficiently large and the currency symbol is at the end" do
|
142
|
+
Money.euro(1_234_567_12).format.should == "1.234.567,12 €"
|
143
|
+
Money.euro(1_234_567_12).format(:no_cents => true).should == "1.234.567 €"
|
144
|
+
end
|
145
|
+
|
146
|
+
describe ":with_currency option" do
|
147
|
+
specify "(:with_currency option => true) works as documented" do
|
148
|
+
Money.ca_dollar(100).format(:with_currency => true).should == "$1.00 CAD"
|
149
|
+
Money.us_dollar(85).format(:with_currency => true).should == "$0.85 USD"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe ":no_cents option" do
|
154
|
+
specify "(:with_currency option => true) works as documented" do
|
155
|
+
Money.ca_dollar(100).format(:no_cents => true).should == "$1"
|
156
|
+
Money.ca_dollar(599).format(:no_cents => true).should == "$5"
|
157
|
+
Money.ca_dollar(570).format(:no_cents => true, :with_currency => true).should == "$5 CAD"
|
158
|
+
Money.ca_dollar(39000).format(:no_cents => true).should == "$390"
|
159
|
+
end
|
160
|
+
|
161
|
+
it "respects :subunit_to_unit currency property" do
|
162
|
+
Money.new(10_00, "BHD").format(:no_cents => true).should == "ب.د1"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe ":no_cents_if_whole option" do
|
167
|
+
specify "(:no_cents_if_whole => true) works as documented" do
|
168
|
+
Money.new(10000, "VUV").format(:no_cents_if_whole => true, :symbol => false).should == "10,000"
|
169
|
+
Money.new(10034, "VUV").format(:no_cents_if_whole => true, :symbol => false).should == "10,034"
|
170
|
+
Money.new(10000, "MGA").format(:no_cents_if_whole => true, :symbol => false).should == "2,000"
|
171
|
+
Money.new(10034, "MGA").format(:no_cents_if_whole => true, :symbol => false).should == "2,006.4"
|
172
|
+
Money.new(10000, "VND").format(:no_cents_if_whole => true, :symbol => false).should == "1.000"
|
173
|
+
Money.new(10034, "VND").format(:no_cents_if_whole => true, :symbol => false).should == "1.003,4"
|
174
|
+
Money.new(10000, "USD").format(:no_cents_if_whole => true, :symbol => false).should == "100"
|
175
|
+
Money.new(10034, "USD").format(:no_cents_if_whole => true, :symbol => false).should == "100.34"
|
176
|
+
Money.new(10000, "IQD").format(:no_cents_if_whole => true, :symbol => false).should == "10"
|
177
|
+
Money.new(10034, "IQD").format(:no_cents_if_whole => true, :symbol => false).should == "10.034"
|
178
|
+
end
|
179
|
+
|
180
|
+
specify "(:no_cents_if_whole => false) works as documented" do
|
181
|
+
Money.new(10000, "VUV").format(:no_cents_if_whole => false, :symbol => false).should == "10,000"
|
182
|
+
Money.new(10034, "VUV").format(:no_cents_if_whole => false, :symbol => false).should == "10,034"
|
183
|
+
Money.new(10000, "MGA").format(:no_cents_if_whole => false, :symbol => false).should == "2,000.0"
|
184
|
+
Money.new(10034, "MGA").format(:no_cents_if_whole => false, :symbol => false).should == "2,006.4"
|
185
|
+
Money.new(10000, "VND").format(:no_cents_if_whole => false, :symbol => false).should == "1.000,0"
|
186
|
+
Money.new(10034, "VND").format(:no_cents_if_whole => false, :symbol => false).should == "1.003,4"
|
187
|
+
Money.new(10000, "USD").format(:no_cents_if_whole => false, :symbol => false).should == "100.00"
|
188
|
+
Money.new(10034, "USD").format(:no_cents_if_whole => false, :symbol => false).should == "100.34"
|
189
|
+
Money.new(10000, "IQD").format(:no_cents_if_whole => false, :symbol => false).should == "10.000"
|
190
|
+
Money.new(10034, "IQD").format(:no_cents_if_whole => false, :symbol => false).should == "10.034"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe ":symbol option" do
|
195
|
+
specify "(:symbol => a symbol string) uses the given value as the money symbol" do
|
196
|
+
Money.new(100, "GBP").format(:symbol => "£").should == "£1.00"
|
197
|
+
end
|
198
|
+
|
199
|
+
specify "(:symbol => true) returns symbol based on the given currency code" do
|
200
|
+
one = Proc.new do |currency|
|
201
|
+
Money.new(100, currency).format(:symbol => true)
|
202
|
+
end
|
203
|
+
|
204
|
+
# Pounds
|
205
|
+
one["GBP"].should == "£1.00"
|
206
|
+
|
207
|
+
# Dollars
|
208
|
+
one["USD"].should == "$1.00"
|
209
|
+
one["CAD"].should == "$1.00"
|
210
|
+
one["AUD"].should == "$1.00"
|
211
|
+
one["NZD"].should == "$1.00"
|
212
|
+
one["ZWD"].should == "$1.00"
|
213
|
+
|
214
|
+
# Yen
|
215
|
+
one["JPY"].should == "¥100"
|
216
|
+
one["CNY"].should == "¥1.00"
|
217
|
+
|
218
|
+
# Euro
|
219
|
+
one["EUR"].should == "1,00 €"
|
220
|
+
|
221
|
+
# Rupees
|
222
|
+
one["INR"].should == "₨1.00"
|
223
|
+
one["NPR"].should == "₨1.00"
|
224
|
+
one["SCR"].should == "1.00 ₨"
|
225
|
+
one["LKR"].should == "1.00 ₨"
|
226
|
+
|
227
|
+
# Brazilian Real
|
228
|
+
one["BRL"].should == "R$ 1,00"
|
229
|
+
|
230
|
+
# Other
|
231
|
+
one["SEK"].should == "kr1.00"
|
232
|
+
one["GHC"].should == "₵1.00"
|
233
|
+
end
|
234
|
+
|
235
|
+
specify "(:symbol => true) returns $ when currency code is not recognized" do
|
236
|
+
currency = Money::Currency.new("EUR")
|
237
|
+
currency.should_receive(:symbol).and_return(nil)
|
238
|
+
Money.new(100, currency).format(:symbol => true).should == "1,00 ¤"
|
239
|
+
end
|
240
|
+
|
241
|
+
specify "(:symbol => some non-Boolean value that evaluates to true) returns symbol based on the given currency code" do
|
242
|
+
Money.new(100, "GBP").format(:symbol => true).should == "£1.00"
|
243
|
+
Money.new(100, "EUR").format(:symbol => true).should == "1,00 €"
|
244
|
+
Money.new(100, "SEK").format(:symbol => true).should == "kr1.00"
|
245
|
+
end
|
246
|
+
|
247
|
+
specify "(:symbol => "", nil or false) returns the amount without a symbol" do
|
248
|
+
money = Money.new(100, "GBP")
|
249
|
+
money.format(:symbol => "").should == "1.00"
|
250
|
+
money.format(:symbol => nil).should == "1.00"
|
251
|
+
money.format(:symbol => false).should == "1.00"
|
252
|
+
end
|
253
|
+
|
254
|
+
it "defaults :symbol to true" do
|
255
|
+
money = Money.new(100)
|
256
|
+
money.format.should == "$1.00"
|
257
|
+
|
258
|
+
money = Money.new(100, "GBP")
|
259
|
+
money.format.should == "£1.00"
|
260
|
+
|
261
|
+
money = Money.new(100, "EUR")
|
262
|
+
money.format.should == "1,00 €"
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe ":decimal_mark option" do
|
267
|
+
specify "(:decimal_mark => a decimal_mark string) works as documented" do
|
268
|
+
Money.us_dollar(100).format(:decimal_mark => ",").should == "$1,00"
|
269
|
+
end
|
270
|
+
|
271
|
+
it "defaults to '.' if currency isn't recognized" do
|
272
|
+
Money.new(100, "ZWD").format.should == "$1.00"
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
describe ":separator option" do
|
277
|
+
specify "(:separator => a separator string) works as documented" do
|
278
|
+
Money.us_dollar(100).format(:separator => ",").should == "$1,00"
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe ":thousands_separator option" do
|
283
|
+
specify "(:thousands_separator => a thousands_separator string) works as documented" do
|
284
|
+
Money.us_dollar(100000).format(:thousands_separator => ".").should == "$1.000.00"
|
285
|
+
Money.us_dollar(200000).format(:thousands_separator => "").should == "$2000.00"
|
286
|
+
end
|
287
|
+
|
288
|
+
specify "(:thousands_separator => false or nil) works as documented" do
|
289
|
+
Money.us_dollar(100000).format(:thousands_separator => false).should == "$1000.00"
|
290
|
+
Money.us_dollar(200000).format(:thousands_separator => nil).should == "$2000.00"
|
291
|
+
end
|
292
|
+
|
293
|
+
specify "(:delimiter => a delimiter string) works as documented" do
|
294
|
+
Money.us_dollar(100000).format(:delimiter => ".").should == "$1.000.00"
|
295
|
+
Money.us_dollar(200000).format(:delimiter => "").should == "$2000.00"
|
296
|
+
end
|
297
|
+
|
298
|
+
specify "(:delimiter => false or nil) works as documented" do
|
299
|
+
Money.us_dollar(100000).format(:delimiter => false).should == "$1000.00"
|
300
|
+
Money.us_dollar(200000).format(:delimiter => nil).should == "$2000.00"
|
301
|
+
end
|
302
|
+
|
303
|
+
it "defaults to ',' if currency isn't recognized" do
|
304
|
+
Money.new(100000, "ZWD").format.should == "$1,000.00"
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
describe ":html option" do
|
309
|
+
specify "(:html => true) works as documented" do
|
310
|
+
string = Money.ca_dollar(570).format(:html => true, :with_currency => true)
|
311
|
+
string.should == "$5.70 <span class=\"currency\">CAD</span>"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe ":symbol_position option" do
|
316
|
+
it "inserts currency symbol before the amount when set to :before" do
|
317
|
+
Money.euro(1_234_567_12).format(:symbol_position => :before).should == "€1.234.567,12"
|
318
|
+
end
|
319
|
+
|
320
|
+
it "inserts currency symbol after the amount when set to :after" do
|
321
|
+
Money.us_dollar(1_000_000_000_12).format(:symbol_position => :after).should == "1,000,000,000.12 $"
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
context "when the monetary value is 0" do
|
326
|
+
let(:money) { Money.us_dollar(0) }
|
327
|
+
|
328
|
+
it "returns 'free' when :display_free is true" do
|
329
|
+
money.format(:display_free => true).should == 'free'
|
330
|
+
end
|
331
|
+
|
332
|
+
it "returns '$0.00' when :display_free is false or not given" do
|
333
|
+
money.format.should == '$0.00'
|
334
|
+
money.format(:display_free => false).should == '$0.00'
|
335
|
+
money.format(:display_free => nil).should == '$0.00'
|
336
|
+
end
|
337
|
+
|
338
|
+
it "returns the value specified by :display_free if it's a string-like object" do
|
339
|
+
money.format(:display_free => 'gratis').should == 'gratis'
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
it "brute forces :subunit_to_unit = 1" do
|
344
|
+
("0".."9").each do |amt|
|
345
|
+
amt.to_money("VUV").format(:symbol => false).should == amt
|
346
|
+
end
|
347
|
+
("-1".."-9").each do |amt|
|
348
|
+
amt.to_money("VUV").format(:symbol => false).should == amt
|
349
|
+
end
|
350
|
+
"1000".to_money("VUV").format(:symbol => false).should == "1,000"
|
351
|
+
"-1000".to_money("VUV").format(:symbol => false).should == "-1,000"
|
352
|
+
end
|
353
|
+
|
354
|
+
it "brute forces :subunit_to_unit = 5" do
|
355
|
+
("0.0".."9.4").each do |amt|
|
356
|
+
next if amt[-1].to_i > 4
|
357
|
+
amt.to_money("MGA").format(:symbol => false).should == amt
|
358
|
+
end
|
359
|
+
("-0.1".."-9.4").each do |amt|
|
360
|
+
next if amt[-1].to_i > 4
|
361
|
+
amt.to_money("MGA").format(:symbol => false).should == amt
|
362
|
+
end
|
363
|
+
"1000.0".to_money("MGA").format(:symbol => false).should == "1,000.0"
|
364
|
+
"-1000.0".to_money("MGA").format(:symbol => false).should == "-1,000.0"
|
365
|
+
end
|
366
|
+
|
367
|
+
it "brute forces :subunit_to_unit = 10" do
|
368
|
+
("0.0".."9.9").each do |amt|
|
369
|
+
amt.to_money("VND").format(:symbol => false).should == amt.to_s.gsub(/\./, ",")
|
370
|
+
end
|
371
|
+
("-0.1".."-9.9").each do |amt|
|
372
|
+
amt.to_money("VND").format(:symbol => false).should == amt.to_s.gsub(/\./, ",")
|
373
|
+
end
|
374
|
+
"1000.0".to_money("VND").format(:symbol => false).should == "1.000,0"
|
375
|
+
"-1000.0".to_money("VND").format(:symbol => false).should == "-1.000,0"
|
376
|
+
end
|
377
|
+
|
378
|
+
it "brute forces :subunit_to_unit = 100" do
|
379
|
+
("0.00".."9.99").each do |amt|
|
380
|
+
amt.to_money("USD").format(:symbol => false).should == amt
|
381
|
+
end
|
382
|
+
("-0.01".."-9.99").each do |amt|
|
383
|
+
amt.to_money("USD").format(:symbol => false).should == amt
|
384
|
+
end
|
385
|
+
"1000.00".to_money("USD").format(:symbol => false).should == "1,000.00"
|
386
|
+
"-1000.00".to_money("USD").format(:symbol => false).should == "-1,000.00"
|
387
|
+
end
|
388
|
+
|
389
|
+
it "brute forces :subunit_to_unit = 1000" do
|
390
|
+
("0.000".."9.999").each do |amt|
|
391
|
+
amt.to_money("IQD").format(:symbol => false).should == amt
|
392
|
+
end
|
393
|
+
("-0.001".."-9.999").each do |amt|
|
394
|
+
amt.to_money("IQD").format(:symbol => false).should == amt
|
395
|
+
end
|
396
|
+
"1000.000".to_money("IQD").format(:symbol => false).should == "1,000.000"
|
397
|
+
"-1000.000".to_money("IQD").format(:symbol => false).should == "-1,000.000"
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
end
|
402
|
+
|