money 6.1.1 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/AUTHORS +6 -0
- data/CHANGELOG.md +16 -0
- data/README.md +30 -1
- data/config/currency_iso.json +6 -6
- data/lib/money/currency.rb +16 -5
- data/lib/money/money/arithmetic.rb +16 -10
- data/lib/money/money/formatting.rb +19 -6
- data/lib/money/money.rb +18 -13
- data/lib/money/version.rb +1 -1
- data/money.gemspec +2 -2
- data/spec/bank/base_spec.rb +11 -11
- data/spec/bank/variable_exchange_spec.rb +37 -37
- data/spec/currency/heuristics_spec.rb +25 -25
- data/spec/currency_spec.rb +56 -57
- data/spec/money/arithmetic_spec.rb +107 -99
- data/spec/money/formatting_spec.rb +230 -181
- data/spec/money_spec.rb +161 -128
- metadata +12 -6
@@ -9,10 +9,15 @@ describe Money, "formatting" do
|
|
9
9
|
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": "." }'
|
10
10
|
|
11
11
|
context "without i18n" do
|
12
|
-
subject { Money.empty("USD") }
|
12
|
+
subject(:money) { Money.empty("USD") }
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
it "should use ',' as the thousands separator" do
|
15
|
+
expect(money.thousands_separator).to eq ','
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should use '.' as the decimal mark" do
|
19
|
+
expect(money.decimal_mark).to eq '.'
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
23
|
context "with i18n but use_i18n = false" do
|
@@ -32,10 +37,15 @@ describe Money, "formatting" do
|
|
32
37
|
Money.use_i18n = true
|
33
38
|
end
|
34
39
|
|
35
|
-
subject { Money.empty("USD") }
|
40
|
+
subject(:money) { Money.empty("USD") }
|
36
41
|
|
37
|
-
|
38
|
-
|
42
|
+
it "should use ',' as the thousands separator" do
|
43
|
+
expect(money.thousands_separator).to eq ','
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should use '.' as the decimal mark" do
|
47
|
+
expect(money.decimal_mark).to eq '.'
|
48
|
+
end
|
39
49
|
end
|
40
50
|
|
41
51
|
context "with i18n" do
|
@@ -54,10 +64,15 @@ describe Money, "formatting" do
|
|
54
64
|
)
|
55
65
|
end
|
56
66
|
|
57
|
-
subject { Money.empty("USD") }
|
67
|
+
subject(:money) { Money.empty("USD") }
|
58
68
|
|
59
|
-
|
60
|
-
|
69
|
+
it "should use '.' as the thousands separator" do
|
70
|
+
expect(money.thousands_separator).to eq '.'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should use ',' as the decimal mark" do
|
74
|
+
expect(money.decimal_mark).to eq ','
|
75
|
+
end
|
61
76
|
end
|
62
77
|
|
63
78
|
context "with number.currency.format.*" do
|
@@ -70,10 +85,15 @@ describe Money, "formatting" do
|
|
70
85
|
)
|
71
86
|
end
|
72
87
|
|
73
|
-
subject { Money.empty("USD") }
|
88
|
+
subject(:money) { Money.empty("USD") }
|
89
|
+
|
90
|
+
it "should use '.' as the thousands separator" do
|
91
|
+
expect(money.thousands_separator).to eq '.'
|
92
|
+
end
|
74
93
|
|
75
|
-
|
76
|
-
|
94
|
+
it "should use ',' as the decimal mark" do
|
95
|
+
expect(money.decimal_mark).to eq ','
|
96
|
+
end
|
77
97
|
end
|
78
98
|
end
|
79
99
|
|
@@ -83,24 +103,24 @@ describe Money, "formatting" do
|
|
83
103
|
|
84
104
|
it "formats Japanese currency in Japanese properly" do
|
85
105
|
money = Money.new(1000, "JPY")
|
86
|
-
money.format.
|
87
|
-
money.format(:symbol => false).
|
106
|
+
expect(money.format).to eq "1,000円"
|
107
|
+
expect(money.format(:symbol => false)).to eq "1,000"
|
88
108
|
end
|
89
109
|
|
90
110
|
after { I18n.locale = @_locale }
|
91
111
|
end
|
92
112
|
|
93
113
|
it "returns the monetary value as a string" do
|
94
|
-
Money.ca_dollar(100).format.
|
95
|
-
Money.new(40008).format.
|
114
|
+
expect(Money.ca_dollar(100).format).to eq "$1.00"
|
115
|
+
expect(Money.new(40008).format).to eq "$400.08"
|
96
116
|
end
|
97
117
|
|
98
118
|
it "respects :subunit_to_unit currency property" do
|
99
|
-
Money.new(10_00, "BHD").format.
|
119
|
+
expect(Money.new(10_00, "BHD").format).to eq "ب.د1.000"
|
100
120
|
end
|
101
121
|
|
102
122
|
it "does not display a decimal when :subunit_to_unit is 1" do
|
103
|
-
Money.new(10_00, "CLP").format.
|
123
|
+
expect(Money.new(10_00, "CLP").format).to eq "$1.000"
|
104
124
|
end
|
105
125
|
|
106
126
|
it "respects the thousands_separator and decimal_mark defaults" do
|
@@ -109,109 +129,109 @@ describe Money, "formatting" do
|
|
109
129
|
end
|
110
130
|
|
111
131
|
# Pounds
|
112
|
-
one_thousand["GBP"].
|
132
|
+
expect(one_thousand["GBP"]).to eq "£1,000.00"
|
113
133
|
|
114
134
|
# Dollars
|
115
|
-
one_thousand["USD"].
|
116
|
-
one_thousand["CAD"].
|
117
|
-
one_thousand["AUD"].
|
118
|
-
one_thousand["NZD"].
|
119
|
-
one_thousand["ZWD"].
|
135
|
+
expect(one_thousand["USD"]).to eq "$1,000.00"
|
136
|
+
expect(one_thousand["CAD"]).to eq "$1,000.00"
|
137
|
+
expect(one_thousand["AUD"]).to eq "$1,000.00"
|
138
|
+
expect(one_thousand["NZD"]).to eq "$1,000.00"
|
139
|
+
expect(one_thousand["ZWD"]).to eq "$1,000.00"
|
120
140
|
|
121
141
|
# Yen
|
122
|
-
one_thousand["JPY"].
|
123
|
-
one_thousand["CNY"].
|
142
|
+
expect(one_thousand["JPY"]).to eq "¥100,000"
|
143
|
+
expect(one_thousand["CNY"]).to eq "¥1,000.00"
|
124
144
|
|
125
145
|
# Euro
|
126
|
-
one_thousand["EUR"].
|
146
|
+
expect(one_thousand["EUR"]).to eq "€1.000,00"
|
127
147
|
|
128
148
|
# Rupees
|
129
|
-
one_thousand["INR"].
|
130
|
-
one_thousand["NPR"].
|
131
|
-
one_thousand["SCR"].
|
132
|
-
one_thousand["LKR"].
|
149
|
+
expect(one_thousand["INR"]).to eq "₹1,000.00"
|
150
|
+
expect(one_thousand["NPR"]).to eq "₨1,000.00"
|
151
|
+
expect(one_thousand["SCR"]).to eq "1,000.00 ₨"
|
152
|
+
expect(one_thousand["LKR"]).to eq "1,000.00 ₨"
|
133
153
|
|
134
154
|
# Brazilian Real
|
135
|
-
one_thousand["BRL"].
|
155
|
+
expect(one_thousand["BRL"]).to eq "R$1.000,00"
|
136
156
|
|
137
157
|
# Other
|
138
|
-
one_thousand["SEK"].
|
139
|
-
one_thousand["GHC"].
|
158
|
+
expect(one_thousand["SEK"]).to eq "1 000,00 kr"
|
159
|
+
expect(one_thousand["GHC"]).to eq "₵1,000.00"
|
140
160
|
end
|
141
161
|
|
142
162
|
it "inserts commas into the result if the amount is sufficiently large" do
|
143
|
-
Money.us_dollar(1_000_000_000_12).format.
|
144
|
-
Money.us_dollar(1_000_000_000_12).format(:no_cents => true).
|
163
|
+
expect(Money.us_dollar(1_000_000_000_12).format).to eq "$1,000,000,000.12"
|
164
|
+
expect(Money.us_dollar(1_000_000_000_12).format(:no_cents => true)).to eq "$1,000,000,000"
|
145
165
|
end
|
146
166
|
|
147
167
|
it "inserts thousands separator into the result if the amount is sufficiently large and the currency symbol is at the end" do
|
148
|
-
Money.euro(1_234_567_12).format.
|
149
|
-
Money.euro(1_234_567_12).format(:no_cents => true).
|
168
|
+
expect(Money.euro(1_234_567_12).format).to eq "€1.234.567,12"
|
169
|
+
expect(Money.euro(1_234_567_12).format(:no_cents => true)).to eq "€1.234.567"
|
150
170
|
end
|
151
171
|
|
152
172
|
describe ":with_currency option" do
|
153
173
|
specify "(:with_currency option => true) works as documented" do
|
154
|
-
Money.ca_dollar(100).format(:with_currency => true).
|
155
|
-
Money.us_dollar(85).format(:with_currency => true).
|
174
|
+
expect(Money.ca_dollar(100).format(:with_currency => true)).to eq "$1.00 CAD"
|
175
|
+
expect(Money.us_dollar(85).format(:with_currency => true)).to eq "$0.85 USD"
|
156
176
|
end
|
157
177
|
end
|
158
178
|
|
159
179
|
describe ":no_cents option" do
|
160
180
|
specify "(:with_currency option => true) works as documented" do
|
161
|
-
Money.ca_dollar(100).format(:no_cents => true).
|
162
|
-
Money.ca_dollar(599).format(:no_cents => true).
|
163
|
-
Money.ca_dollar(570).format(:no_cents => true, :with_currency => true).
|
164
|
-
Money.ca_dollar(39000).format(:no_cents => true).
|
181
|
+
expect(Money.ca_dollar(100).format(:no_cents => true)).to eq "$1"
|
182
|
+
expect(Money.ca_dollar(599).format(:no_cents => true)).to eq "$5"
|
183
|
+
expect(Money.ca_dollar(570).format(:no_cents => true, :with_currency => true)).to eq "$5 CAD"
|
184
|
+
expect(Money.ca_dollar(39000).format(:no_cents => true)).to eq "$390"
|
165
185
|
end
|
166
186
|
|
167
187
|
it "respects :subunit_to_unit currency property" do
|
168
|
-
Money.new(10_00, "BHD").format(:no_cents => true).
|
188
|
+
expect(Money.new(10_00, "BHD").format(:no_cents => true)).to eq "ب.د1"
|
169
189
|
end
|
170
190
|
|
171
191
|
it "inserts thousand separators if symbol contains decimal mark and no_cents is true" do
|
172
|
-
Money.new(100000000, "AMD").format(:no_cents => true).
|
173
|
-
Money.new(100000000, "USD").format(:no_cents => true).
|
174
|
-
Money.new(100000000, "RUB").format(:no_cents => true).
|
192
|
+
expect(Money.new(100000000, "AMD").format(:no_cents => true)).to eq "1,000,000 դր."
|
193
|
+
expect(Money.new(100000000, "USD").format(:no_cents => true)).to eq "$1,000,000"
|
194
|
+
expect(Money.new(100000000, "RUB").format(:no_cents => true)).to eq "1.000.000 р."
|
175
195
|
end
|
176
196
|
|
177
197
|
it "doesn't incorrectly format HTML" do
|
178
198
|
money = ::Money.new(1999, "RUB")
|
179
199
|
output = money.format(:html => true, :no_cents => true)
|
180
|
-
output.
|
200
|
+
expect(output).to eq "19 руб"
|
181
201
|
end
|
182
202
|
end
|
183
203
|
|
184
204
|
describe ":no_cents_if_whole option" do
|
185
205
|
specify "(:no_cents_if_whole => true) works as documented" do
|
186
|
-
Money.new(10000, "VUV").format(:no_cents_if_whole => true, :symbol => false).
|
187
|
-
Money.new(10034, "VUV").format(:no_cents_if_whole => true, :symbol => false).
|
188
|
-
Money.new(10000, "MGA").format(:no_cents_if_whole => true, :symbol => false).
|
189
|
-
Money.new(10034, "MGA").format(:no_cents_if_whole => true, :symbol => false).
|
190
|
-
Money.new(10000, "VND").format(:no_cents_if_whole => true, :symbol => false).
|
191
|
-
Money.new(10034, "VND").format(:no_cents_if_whole => true, :symbol => false).
|
192
|
-
Money.new(10000, "USD").format(:no_cents_if_whole => true, :symbol => false).
|
193
|
-
Money.new(10034, "USD").format(:no_cents_if_whole => true, :symbol => false).
|
194
|
-
Money.new(10000, "IQD").format(:no_cents_if_whole => true, :symbol => false).
|
195
|
-
Money.new(10034, "IQD").format(:no_cents_if_whole => true, :symbol => false).
|
206
|
+
expect(Money.new(10000, "VUV").format(:no_cents_if_whole => true, :symbol => false)).to eq "10,000"
|
207
|
+
expect(Money.new(10034, "VUV").format(:no_cents_if_whole => true, :symbol => false)).to eq "10,034"
|
208
|
+
expect(Money.new(10000, "MGA").format(:no_cents_if_whole => true, :symbol => false)).to eq "2,000"
|
209
|
+
expect(Money.new(10034, "MGA").format(:no_cents_if_whole => true, :symbol => false)).to eq "2,006.4"
|
210
|
+
expect(Money.new(10000, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "1.000"
|
211
|
+
expect(Money.new(10034, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "1.003,4"
|
212
|
+
expect(Money.new(10000, "USD").format(:no_cents_if_whole => true, :symbol => false)).to eq "100"
|
213
|
+
expect(Money.new(10034, "USD").format(:no_cents_if_whole => true, :symbol => false)).to eq "100.34"
|
214
|
+
expect(Money.new(10000, "IQD").format(:no_cents_if_whole => true, :symbol => false)).to eq "10"
|
215
|
+
expect(Money.new(10034, "IQD").format(:no_cents_if_whole => true, :symbol => false)).to eq "10.034"
|
196
216
|
end
|
197
217
|
|
198
218
|
specify "(:no_cents_if_whole => false) works as documented" do
|
199
|
-
Money.new(10000, "VUV").format(:no_cents_if_whole => false, :symbol => false).
|
200
|
-
Money.new(10034, "VUV").format(:no_cents_if_whole => false, :symbol => false).
|
201
|
-
Money.new(10000, "MGA").format(:no_cents_if_whole => false, :symbol => false).
|
202
|
-
Money.new(10034, "MGA").format(:no_cents_if_whole => false, :symbol => false).
|
203
|
-
Money.new(10000, "VND").format(:no_cents_if_whole => false, :symbol => false).
|
204
|
-
Money.new(10034, "VND").format(:no_cents_if_whole => false, :symbol => false).
|
205
|
-
Money.new(10000, "USD").format(:no_cents_if_whole => false, :symbol => false).
|
206
|
-
Money.new(10034, "USD").format(:no_cents_if_whole => false, :symbol => false).
|
207
|
-
Money.new(10000, "IQD").format(:no_cents_if_whole => false, :symbol => false).
|
208
|
-
Money.new(10034, "IQD").format(:no_cents_if_whole => false, :symbol => false).
|
219
|
+
expect(Money.new(10000, "VUV").format(:no_cents_if_whole => false, :symbol => false)).to eq "10,000"
|
220
|
+
expect(Money.new(10034, "VUV").format(:no_cents_if_whole => false, :symbol => false)).to eq "10,034"
|
221
|
+
expect(Money.new(10000, "MGA").format(:no_cents_if_whole => false, :symbol => false)).to eq "2,000.0"
|
222
|
+
expect(Money.new(10034, "MGA").format(:no_cents_if_whole => false, :symbol => false)).to eq "2,006.4"
|
223
|
+
expect(Money.new(10000, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "1.000,0"
|
224
|
+
expect(Money.new(10034, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "1.003,4"
|
225
|
+
expect(Money.new(10000, "USD").format(:no_cents_if_whole => false, :symbol => false)).to eq "100.00"
|
226
|
+
expect(Money.new(10034, "USD").format(:no_cents_if_whole => false, :symbol => false)).to eq "100.34"
|
227
|
+
expect(Money.new(10000, "IQD").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.000"
|
228
|
+
expect(Money.new(10034, "IQD").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.034"
|
209
229
|
end
|
210
230
|
end
|
211
231
|
|
212
232
|
describe ":symbol option" do
|
213
233
|
specify "(:symbol => a symbol string) uses the given value as the money symbol" do
|
214
|
-
Money.new(100, "GBP").format(:symbol => "£").
|
234
|
+
expect(Money.new(100, "GBP").format(:symbol => "£")).to eq "£1.00"
|
215
235
|
end
|
216
236
|
|
217
237
|
specify "(:symbol => true) returns symbol based on the given currency code" do
|
@@ -220,92 +240,92 @@ describe Money, "formatting" do
|
|
220
240
|
end
|
221
241
|
|
222
242
|
# Pounds
|
223
|
-
one["GBP"].
|
243
|
+
expect(one["GBP"]).to eq "£1.00"
|
224
244
|
|
225
245
|
# Dollars
|
226
|
-
one["USD"].
|
227
|
-
one["CAD"].
|
228
|
-
one["AUD"].
|
229
|
-
one["NZD"].
|
230
|
-
one["ZWD"].
|
246
|
+
expect(one["USD"]).to eq "$1.00"
|
247
|
+
expect(one["CAD"]).to eq "$1.00"
|
248
|
+
expect(one["AUD"]).to eq "$1.00"
|
249
|
+
expect(one["NZD"]).to eq "$1.00"
|
250
|
+
expect(one["ZWD"]).to eq "$1.00"
|
231
251
|
|
232
252
|
# Yen
|
233
|
-
one["JPY"].
|
234
|
-
one["CNY"].
|
253
|
+
expect(one["JPY"]).to eq "¥100"
|
254
|
+
expect(one["CNY"]).to eq "¥1.00"
|
235
255
|
|
236
256
|
# Euro
|
237
|
-
one["EUR"].
|
257
|
+
expect(one["EUR"]).to eq "€1,00"
|
238
258
|
|
239
259
|
# Rupees
|
240
|
-
one["INR"].
|
241
|
-
one["NPR"].
|
242
|
-
one["SCR"].
|
243
|
-
one["LKR"].
|
260
|
+
expect(one["INR"]).to eq "₹1.00"
|
261
|
+
expect(one["NPR"]).to eq "₨1.00"
|
262
|
+
expect(one["SCR"]).to eq "1.00 ₨"
|
263
|
+
expect(one["LKR"]).to eq "1.00 ₨"
|
244
264
|
|
245
265
|
# Brazilian Real
|
246
|
-
one["BRL"].
|
266
|
+
expect(one["BRL"]).to eq "R$1,00"
|
247
267
|
|
248
268
|
# Other
|
249
|
-
one["SEK"].
|
250
|
-
one["GHC"].
|
269
|
+
expect(one["SEK"]).to eq "1,00 kr"
|
270
|
+
expect(one["GHC"]).to eq "₵1.00"
|
251
271
|
end
|
252
272
|
|
253
273
|
specify "(:symbol => true) returns $ when currency code is not recognized" do
|
254
274
|
currency = Money::Currency.new("EUR")
|
255
|
-
currency.
|
256
|
-
Money.new(100, currency).format(:symbol => true).
|
275
|
+
expect(currency).to receive(:symbol).and_return(nil)
|
276
|
+
expect(Money.new(100, currency).format(:symbol => true)).to eq "¤1,00"
|
257
277
|
end
|
258
278
|
|
259
279
|
specify "(:symbol => some non-Boolean value that evaluates to true) returns symbol based on the given currency code" do
|
260
|
-
Money.new(100, "GBP").format(:symbol => true).
|
261
|
-
Money.new(100, "EUR").format(:symbol => true).
|
262
|
-
Money.new(100, "SEK").format(:symbol => true).
|
280
|
+
expect(Money.new(100, "GBP").format(:symbol => true)).to eq "£1.00"
|
281
|
+
expect(Money.new(100, "EUR").format(:symbol => true)).to eq "€1,00"
|
282
|
+
expect(Money.new(100, "SEK").format(:symbol => true)).to eq "1,00 kr"
|
263
283
|
end
|
264
284
|
|
265
285
|
specify "(:symbol => "", nil or false) returns the amount without a symbol" do
|
266
286
|
money = Money.new(100, "GBP")
|
267
|
-
money.format(:symbol => "").
|
268
|
-
money.format(:symbol => nil).
|
269
|
-
money.format(:symbol => false).
|
287
|
+
expect(money.format(:symbol => "")).to eq "1.00"
|
288
|
+
expect(money.format(:symbol => nil)).to eq "1.00"
|
289
|
+
expect(money.format(:symbol => false)).to eq "1.00"
|
270
290
|
|
271
291
|
money = Money.new(100, "JPY")
|
272
|
-
money.format(:symbol => false).
|
292
|
+
expect(money.format(:symbol => false)).to eq "100"
|
273
293
|
end
|
274
294
|
|
275
295
|
it "defaults :symbol to true" do
|
276
296
|
money = Money.new(100)
|
277
|
-
money.format.
|
297
|
+
expect(money.format).to eq "$1.00"
|
278
298
|
|
279
299
|
money = Money.new(100, "GBP")
|
280
|
-
money.format.
|
300
|
+
expect(money.format).to eq "£1.00"
|
281
301
|
|
282
302
|
money = Money.new(100, "EUR")
|
283
|
-
money.format.
|
303
|
+
expect(money.format).to eq "€1,00"
|
284
304
|
end
|
285
305
|
|
286
306
|
specify "(:symbol => false) returns a signed amount without a symbol" do
|
287
307
|
money = Money.new(-100, "EUR")
|
288
|
-
money.format(:symbol => false).
|
308
|
+
expect(money.format(:symbol => false)).to eq "-1,00"
|
289
309
|
|
290
310
|
money = Money.new(100, "EUR")
|
291
|
-
money.format(:symbol => false,
|
292
|
-
:sign_positive => true).
|
311
|
+
expect(money.format(:symbol => false,
|
312
|
+
:sign_positive => true)).to eq "+1,00"
|
293
313
|
end
|
294
314
|
end
|
295
315
|
|
296
316
|
describe ":decimal_mark option" do
|
297
317
|
specify "(:decimal_mark => a decimal_mark string) works as documented" do
|
298
|
-
Money.us_dollar(100).format(:decimal_mark => ",").
|
318
|
+
expect(Money.us_dollar(100).format(:decimal_mark => ",")).to eq "$1,00"
|
299
319
|
end
|
300
320
|
|
301
321
|
it "defaults to '.' if currency isn't recognized" do
|
302
|
-
Money.new(100, "ZWD").format.
|
322
|
+
expect(Money.new(100, "ZWD").format).to eq "$1.00"
|
303
323
|
end
|
304
324
|
end
|
305
325
|
|
306
326
|
describe ":separator option" do
|
307
327
|
specify "(:separator => a separator string) works as documented" do
|
308
|
-
Money.us_dollar(100).format(:separator => ",").
|
328
|
+
expect(Money.us_dollar(100).format(:separator => ",")).to eq "$1,00"
|
309
329
|
end
|
310
330
|
end
|
311
331
|
|
@@ -319,131 +339,138 @@ describe Money, "formatting" do
|
|
319
339
|
end
|
320
340
|
|
321
341
|
specify "(:south_asian_number_formatting => true) works as documented" do
|
322
|
-
Money.new(10000000, 'INR').format(:south_asian_number_formatting => true, :symbol => false).
|
323
|
-
Money.new(1000000000, 'INDIAN_BAR').format(:south_asian_number_formatting => true, :symbol => false).
|
324
|
-
Money.new(10000000).format(:south_asian_number_formatting => true).
|
342
|
+
expect(Money.new(10000000, 'INR').format(:south_asian_number_formatting => true, :symbol => false)).to eq "1,00,000.00"
|
343
|
+
expect(Money.new(1000000000, 'INDIAN_BAR').format(:south_asian_number_formatting => true, :symbol => false)).to eq "1,00,000.0000"
|
344
|
+
expect(Money.new(10000000).format(:south_asian_number_formatting => true)).to eq "$1,00,000.00"
|
325
345
|
end
|
326
346
|
end
|
327
347
|
|
328
348
|
describe ":thousands_separator option" do
|
329
349
|
specify "(:thousands_separator => a thousands_separator string) works as documented" do
|
330
|
-
Money.us_dollar(100000).format(:thousands_separator => ".").
|
331
|
-
Money.us_dollar(200000).format(:thousands_separator => "").
|
350
|
+
expect(Money.us_dollar(100000).format(:thousands_separator => ".")).to eq "$1.000.00"
|
351
|
+
expect(Money.us_dollar(200000).format(:thousands_separator => "")).to eq "$2000.00"
|
332
352
|
end
|
333
353
|
|
334
354
|
specify "(:thousands_separator => false or nil) works as documented" do
|
335
|
-
Money.us_dollar(100000).format(:thousands_separator => false).
|
336
|
-
Money.us_dollar(200000).format(:thousands_separator => nil).
|
355
|
+
expect(Money.us_dollar(100000).format(:thousands_separator => false)).to eq "$1000.00"
|
356
|
+
expect(Money.us_dollar(200000).format(:thousands_separator => nil)).to eq "$2000.00"
|
337
357
|
end
|
338
358
|
|
339
359
|
specify "(:delimiter => a delimiter string) works as documented" do
|
340
|
-
Money.us_dollar(100000).format(:delimiter => ".").
|
341
|
-
Money.us_dollar(200000).format(:delimiter => "").
|
360
|
+
expect(Money.us_dollar(100000).format(:delimiter => ".")).to eq "$1.000.00"
|
361
|
+
expect(Money.us_dollar(200000).format(:delimiter => "")).to eq "$2000.00"
|
342
362
|
end
|
343
363
|
|
344
364
|
specify "(:delimiter => false or nil) works as documented" do
|
345
|
-
Money.us_dollar(100000).format(:delimiter => false).
|
346
|
-
Money.us_dollar(200000).format(:delimiter => nil).
|
365
|
+
expect(Money.us_dollar(100000).format(:delimiter => false)).to eq "$1000.00"
|
366
|
+
expect(Money.us_dollar(200000).format(:delimiter => nil)).to eq "$2000.00"
|
347
367
|
end
|
348
368
|
|
349
369
|
it "defaults to ',' if currency isn't recognized" do
|
350
|
-
Money.new(100000, "ZWD").format.
|
370
|
+
expect(Money.new(100000, "ZWD").format).to eq "$1,000.00"
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
describe ":thousands_separator and :decimal_mark option" do
|
375
|
+
specify "(:thousands_separator => a thousands_separator string, :decimal_mark => a decimal_mark string) works as documented" do
|
376
|
+
expect(Money.new(123_456_789, "USD").format(thousands_separator: ".", decimal_mark: ",")).to eq("$1.234.567,89")
|
377
|
+
expect(Money.new(987_654_321, "USD").format(thousands_separator: " ", decimal_mark: ".")).to eq("$9 876 543.21")
|
351
378
|
end
|
352
379
|
end
|
353
380
|
|
354
381
|
describe ":html option" do
|
355
382
|
specify "(:html => true) works as documented" do
|
356
383
|
string = Money.ca_dollar(570).format(:html => true, :with_currency => true)
|
357
|
-
string.
|
384
|
+
expect(string).to eq "$5.70 <span class=\"currency\">CAD</span>"
|
358
385
|
end
|
359
386
|
|
360
387
|
specify "should fallback to symbol if entity is not available" do
|
361
388
|
string = Money.new(570, 'DKK').format(:html => true)
|
362
|
-
string.
|
389
|
+
expect(string).to eq "5,70 kr"
|
363
390
|
end
|
364
391
|
end
|
365
392
|
|
366
393
|
describe ":html_wrap_symbol option" do
|
367
394
|
specify "(:html_wrap_symbol => true) works as documented" do
|
368
395
|
string = Money.ca_dollar(570).format(:html_wrap_symbol => true)
|
369
|
-
string.
|
396
|
+
expect(string).to eq "<span class=\"currency_symbol\">$</span>5.70"
|
370
397
|
end
|
371
398
|
end
|
372
399
|
|
373
400
|
describe ":symbol_position option" do
|
374
401
|
it "inserts currency symbol before the amount when set to :before" do
|
375
|
-
Money.euro(1_234_567_12).format(:symbol_position => :before).
|
402
|
+
expect(Money.euro(1_234_567_12).format(:symbol_position => :before)).to eq "€1.234.567,12"
|
376
403
|
end
|
377
404
|
|
378
405
|
it "inserts currency symbol after the amount when set to :after" do
|
379
|
-
Money.us_dollar(1_000_000_000_12).format(:symbol_position => :after).
|
406
|
+
expect(Money.us_dollar(1_000_000_000_12).format(:symbol_position => :after)).to eq "1,000,000,000.12 $"
|
380
407
|
end
|
381
408
|
end
|
382
409
|
|
383
410
|
describe ":sign_before_symbol option" do
|
384
411
|
specify "(:sign_before_symbol => true) works as documented" do
|
385
|
-
Money.us_dollar(-100000).format(:sign_before_symbol => true).
|
412
|
+
expect(Money.us_dollar(-100000).format(:sign_before_symbol => true)).to eq "-$1,000.00"
|
386
413
|
end
|
387
414
|
|
388
415
|
specify "(:sign_before_symbol => false) works as documented" do
|
389
|
-
Money.us_dollar(-100000).format(:sign_before_symbol => false).
|
390
|
-
Money.us_dollar(-100000).format(:sign_before_symbol => nil).
|
416
|
+
expect(Money.us_dollar(-100000).format(:sign_before_symbol => false)).to eq "$-1,000.00"
|
417
|
+
expect(Money.us_dollar(-100000).format(:sign_before_symbol => nil)).to eq "$-1,000.00"
|
391
418
|
end
|
392
419
|
end
|
393
420
|
|
394
421
|
describe ":symbol_before_without_space option" do
|
395
422
|
it "does not insert space between currency symbol and amount when set to true" do
|
396
|
-
Money.euro(1_234_567_12).format(:symbol_position => :before, :symbol_before_without_space => true).
|
423
|
+
expect(Money.euro(1_234_567_12).format(:symbol_position => :before, :symbol_before_without_space => true)).to eq "€1.234.567,12"
|
397
424
|
end
|
398
425
|
|
399
426
|
it "inserts space between currency symbol and amount when set to false" do
|
400
|
-
Money.euro(1_234_567_12).format(:symbol_position => :before, :symbol_before_without_space => false).
|
427
|
+
expect(Money.euro(1_234_567_12).format(:symbol_position => :before, :symbol_before_without_space => false)).to eq "€ 1.234.567,12"
|
401
428
|
end
|
402
429
|
|
403
430
|
it "defaults to true" do
|
404
|
-
Money.euro(1_234_567_12).format(:symbol_position => :before).
|
431
|
+
expect(Money.euro(1_234_567_12).format(:symbol_position => :before)).to eq "€1.234.567,12"
|
405
432
|
end
|
406
433
|
end
|
407
434
|
|
408
435
|
describe ":symbol_after_without_space option" do
|
409
436
|
it "does not insert space between amount and currency symbol when set to true" do
|
410
|
-
Money.euro(1_234_567_12).format(:symbol_position => :after, :symbol_after_without_space => true).
|
437
|
+
expect(Money.euro(1_234_567_12).format(:symbol_position => :after, :symbol_after_without_space => true)).to eq "1.234.567,12€"
|
411
438
|
end
|
412
439
|
|
413
440
|
it "inserts space between amount and currency symbol when set to false" do
|
414
|
-
Money.euro(1_234_567_12).format(:symbol_position => :after, :symbol_after_without_space => false).
|
441
|
+
expect(Money.euro(1_234_567_12).format(:symbol_position => :after, :symbol_after_without_space => false)).to eq "1.234.567,12 €"
|
415
442
|
end
|
416
443
|
|
417
444
|
it "defaults to false" do
|
418
|
-
Money.euro(1_234_567_12).format(:symbol_position => :after).
|
445
|
+
expect(Money.euro(1_234_567_12).format(:symbol_position => :after)).to eq "1.234.567,12 €"
|
419
446
|
end
|
420
447
|
end
|
421
448
|
|
422
449
|
describe ":sign_positive option" do
|
423
450
|
specify "(:sign_positive => true, :sign_before_symbol => true) works as documented" do
|
424
|
-
Money.us_dollar( 0).format(:sign_positive => true, :sign_before_symbol => true).
|
425
|
-
Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => true).
|
426
|
-
Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => true).
|
451
|
+
expect(Money.us_dollar( 0).format(:sign_positive => true, :sign_before_symbol => true)).to eq "$0.00"
|
452
|
+
expect(Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => true)).to eq "+$1,000.00"
|
453
|
+
expect(Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => true)).to eq "-$1,000.00"
|
427
454
|
end
|
428
455
|
|
429
456
|
specify "(:sign_positive => true, :sign_before_symbol => false) works as documented" do
|
430
|
-
Money.us_dollar( 0).format(:sign_positive => true, :sign_before_symbol => false).
|
431
|
-
Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => false).
|
432
|
-
Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => nil).
|
433
|
-
Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => false).
|
434
|
-
Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => nil).
|
457
|
+
expect(Money.us_dollar( 0).format(:sign_positive => true, :sign_before_symbol => false)).to eq "$0.00"
|
458
|
+
expect(Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => false)).to eq "$+1,000.00"
|
459
|
+
expect(Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => nil)).to eq "$+1,000.00"
|
460
|
+
expect(Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => false)).to eq "$-1,000.00"
|
461
|
+
expect(Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => nil)).to eq "$-1,000.00"
|
435
462
|
end
|
436
463
|
|
437
464
|
specify "(:sign_positive => false, :sign_before_symbol => true) works as documented" do
|
438
|
-
Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => true).
|
439
|
-
Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => true).
|
465
|
+
expect(Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => true)).to eq "$1,000.00"
|
466
|
+
expect(Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => true)).to eq "-$1,000.00"
|
440
467
|
end
|
441
468
|
|
442
469
|
specify "(:sign_positive => false, :sign_before_symbol => false) works as documented" do
|
443
|
-
Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => false).
|
444
|
-
Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => nil).
|
445
|
-
Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => false).
|
446
|
-
Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => nil).
|
470
|
+
expect(Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => false)).to eq "$1,000.00"
|
471
|
+
expect(Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => nil)).to eq "$1,000.00"
|
472
|
+
expect(Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => false)).to eq "$-1,000.00"
|
473
|
+
expect(Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => nil)).to eq "$-1,000.00"
|
447
474
|
end
|
448
475
|
end
|
449
476
|
|
@@ -457,23 +484,45 @@ describe Money, "formatting" do
|
|
457
484
|
end
|
458
485
|
|
459
486
|
it "does round fractional when set to true" do
|
460
|
-
Money.new(BigDecimal.new('12.1'), "USD").format(:rounded_infinite_precision => true).
|
461
|
-
Money.new(BigDecimal.new('12.5'), "USD").format(:rounded_infinite_precision => true).
|
462
|
-
Money.new(BigDecimal.new('123.1'), "BHD").format(:rounded_infinite_precision => true).
|
463
|
-
Money.new(BigDecimal.new('123.5'), "BHD").format(:rounded_infinite_precision => true).
|
464
|
-
Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => true).
|
465
|
-
Money.new(BigDecimal.new('109.5'), "USD").format(:rounded_infinite_precision => true).
|
466
|
-
Money.new(BigDecimal.new('1'), "MGA").format(:rounded_infinite_precision => true).
|
487
|
+
expect(Money.new(BigDecimal.new('12.1'), "USD").format(:rounded_infinite_precision => true)).to eq "$0.12"
|
488
|
+
expect(Money.new(BigDecimal.new('12.5'), "USD").format(:rounded_infinite_precision => true)).to eq "$0.13"
|
489
|
+
expect(Money.new(BigDecimal.new('123.1'), "BHD").format(:rounded_infinite_precision => true)).to eq "ب.د0.123"
|
490
|
+
expect(Money.new(BigDecimal.new('123.5'), "BHD").format(:rounded_infinite_precision => true)).to eq "ب.د0.124"
|
491
|
+
expect(Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => true)).to eq "$1.00"
|
492
|
+
expect(Money.new(BigDecimal.new('109.5'), "USD").format(:rounded_infinite_precision => true)).to eq "$1.10"
|
493
|
+
expect(Money.new(BigDecimal.new('1'), "MGA").format(:rounded_infinite_precision => true)).to eq "Ar0.2"
|
467
494
|
end
|
468
495
|
|
469
496
|
it "does not round fractional when set to false" do
|
470
|
-
Money.new(BigDecimal.new('12.1'), "USD").format(:rounded_infinite_precision => false).
|
471
|
-
Money.new(BigDecimal.new('12.5'), "USD").format(:rounded_infinite_precision => false).
|
472
|
-
Money.new(BigDecimal.new('123.1'), "BHD").format(:rounded_infinite_precision => false).
|
473
|
-
Money.new(BigDecimal.new('123.5'), "BHD").format(:rounded_infinite_precision => false).
|
474
|
-
Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => false).
|
475
|
-
Money.new(BigDecimal.new('109.5'), "USD").format(:rounded_infinite_precision => false).
|
476
|
-
Money.new(BigDecimal.new('1'), "MGA").format(:rounded_infinite_precision => false).
|
497
|
+
expect(Money.new(BigDecimal.new('12.1'), "USD").format(:rounded_infinite_precision => false)).to eq "$0.121"
|
498
|
+
expect(Money.new(BigDecimal.new('12.5'), "USD").format(:rounded_infinite_precision => false)).to eq "$0.125"
|
499
|
+
expect(Money.new(BigDecimal.new('123.1'), "BHD").format(:rounded_infinite_precision => false)).to eq "ب.د0.1231"
|
500
|
+
expect(Money.new(BigDecimal.new('123.5'), "BHD").format(:rounded_infinite_precision => false)).to eq "ب.د0.1235"
|
501
|
+
expect(Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => false)).to eq "$1.001"
|
502
|
+
expect(Money.new(BigDecimal.new('109.5'), "USD").format(:rounded_infinite_precision => false)).to eq "$1.095"
|
503
|
+
expect(Money.new(BigDecimal.new('1'), "MGA").format(:rounded_infinite_precision => false)).to eq "Ar0.1"
|
504
|
+
end
|
505
|
+
|
506
|
+
describe ":rounded_infinite_precision option with i18n = false" do
|
507
|
+
before do
|
508
|
+
Money.use_i18n = false
|
509
|
+
Money.infinite_precision = true
|
510
|
+
end
|
511
|
+
|
512
|
+
after do
|
513
|
+
Money.use_i18n = true
|
514
|
+
Money.infinite_precision = false
|
515
|
+
end
|
516
|
+
|
517
|
+
it 'does round fractional when set to true' do
|
518
|
+
expect(Money.new(BigDecimal.new('12.1'), "EUR").format(:rounded_infinite_precision => true)).to eq "€0,12"
|
519
|
+
expect(Money.new(BigDecimal.new('12.5'), "EUR").format(:rounded_infinite_precision => true)).to eq "€0,13"
|
520
|
+
expect(Money.new(BigDecimal.new('100.1'), "EUR").format(:rounded_infinite_precision => true)).to eq "€1,00"
|
521
|
+
expect(Money.new(BigDecimal.new('109.5'), "EUR").format(:rounded_infinite_precision => true)).to eq "€1,10"
|
522
|
+
|
523
|
+
expect(Money.new(BigDecimal.new('100012.1'), "EUR").format(:rounded_infinite_precision => true)).to eq "€1.000,12"
|
524
|
+
expect(Money.new(BigDecimal.new('100012.5'), "EUR").format(:rounded_infinite_precision => true)).to eq "€1.000,13"
|
525
|
+
end
|
477
526
|
end
|
478
527
|
end
|
479
528
|
|
@@ -481,17 +530,17 @@ describe Money, "formatting" do
|
|
481
530
|
let(:money) { Money.us_dollar(0) }
|
482
531
|
|
483
532
|
it "returns 'free' when :display_free is true" do
|
484
|
-
money.format(:display_free => true).
|
533
|
+
expect(money.format(:display_free => true)).to eq 'free'
|
485
534
|
end
|
486
535
|
|
487
536
|
it "returns '$0.00' when :display_free is false or not given" do
|
488
|
-
money.format.
|
489
|
-
money.format(:display_free => false).
|
490
|
-
money.format(:display_free => nil).
|
537
|
+
expect(money.format).to eq '$0.00'
|
538
|
+
expect(money.format(:display_free => false)).to eq '$0.00'
|
539
|
+
expect(money.format(:display_free => nil)).to eq '$0.00'
|
491
540
|
end
|
492
541
|
|
493
542
|
it "returns the value specified by :display_free if it's a string-like object" do
|
494
|
-
money.format(:display_free => 'gratis').
|
543
|
+
expect(money.format(:display_free => 'gratis')).to eq 'gratis'
|
495
544
|
end
|
496
545
|
end
|
497
546
|
end
|
@@ -508,32 +557,32 @@ describe Money, "formatting" do
|
|
508
557
|
end
|
509
558
|
|
510
559
|
it "respects custom subunit to unit, decimal and thousands separator" do
|
511
|
-
Money.new(4, "BAR").format.
|
512
|
-
Money.new(4, "EU4").format.
|
560
|
+
expect(Money.new(4, "BAR").format).to eq "$0.0004"
|
561
|
+
expect(Money.new(4, "EU4").format).to eq "€0,0004"
|
513
562
|
|
514
|
-
Money.new(24, "BAR").format.
|
515
|
-
Money.new(24, "EU4").format.
|
563
|
+
expect(Money.new(24, "BAR").format).to eq "$0.0024"
|
564
|
+
expect(Money.new(24, "EU4").format).to eq "€0,0024"
|
516
565
|
|
517
|
-
Money.new(324, "BAR").format.
|
518
|
-
Money.new(324, "EU4").format.
|
566
|
+
expect(Money.new(324, "BAR").format).to eq "$0.0324"
|
567
|
+
expect(Money.new(324, "EU4").format).to eq "€0,0324"
|
519
568
|
|
520
|
-
Money.new(5324, "BAR").format.
|
521
|
-
Money.new(5324, "EU4").format.
|
569
|
+
expect(Money.new(5324, "BAR").format).to eq "$0.5324"
|
570
|
+
expect(Money.new(5324, "EU4").format).to eq "€0,5324"
|
522
571
|
|
523
|
-
Money.new(65324, "BAR").format.
|
524
|
-
Money.new(65324, "EU4").format.
|
572
|
+
expect(Money.new(65324, "BAR").format).to eq "$6.5324"
|
573
|
+
expect(Money.new(65324, "EU4").format).to eq "€6,5324"
|
525
574
|
|
526
|
-
Money.new(865324, "BAR").format.
|
527
|
-
Money.new(865324, "EU4").format.
|
575
|
+
expect(Money.new(865324, "BAR").format).to eq "$86.5324"
|
576
|
+
expect(Money.new(865324, "EU4").format).to eq "€86,5324"
|
528
577
|
|
529
|
-
Money.new(1865324, "BAR").format.
|
530
|
-
Money.new(1865324, "EU4").format.
|
578
|
+
expect(Money.new(1865324, "BAR").format).to eq "$186.5324"
|
579
|
+
expect(Money.new(1865324, "EU4").format).to eq "€186,5324"
|
531
580
|
|
532
|
-
Money.new(33310034, "BAR").format.
|
533
|
-
Money.new(33310034, "EU4").format.
|
581
|
+
expect(Money.new(33310034, "BAR").format).to eq "$3,331.0034"
|
582
|
+
expect(Money.new(33310034, "EU4").format).to eq "€3.331,0034"
|
534
583
|
|
535
|
-
Money.new(88833310034, "BAR").format.
|
536
|
-
Money.new(88833310034, "EU4").format.
|
584
|
+
expect(Money.new(88833310034, "BAR").format).to eq "$8,883,331.0034"
|
585
|
+
expect(Money.new(88833310034, "EU4").format).to eq "€8.883.331,0034"
|
537
586
|
end
|
538
587
|
|
539
588
|
end
|