money 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +9 -0
- data/README.rdoc +92 -10
- data/Rakefile +7 -2
- data/VERSION +1 -1
- data/lib/money/core_extensions.rb +7 -1
- data/lib/money/currency.rb +289 -0
- data/lib/money/defaults.rb +55 -29
- data/lib/money/money.rb +58 -24
- data/lib/money/variable_exchange_bank.rb +1 -1
- data/money.gemspec +9 -4
- data/test/core_extensions_spec.rb +18 -6
- data/test/currency_spec.rb +113 -0
- data/test/money_spec.rb +80 -19
- metadata +33 -13
data/test/money_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe Money do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
specify "#currency returns the currency passed to the constructor" do
|
22
|
-
Money.new(200_00, "USD").currency.should == "USD"
|
22
|
+
Money.new(200_00, "USD").currency.should == Money::Currency.new("USD")
|
23
23
|
end
|
24
24
|
|
25
25
|
specify "#zero? returns whether the amount is 0" do
|
@@ -32,13 +32,13 @@ describe Money do
|
|
32
32
|
|
33
33
|
specify "#exchange_to exchanges the amount via its exchange bank" do
|
34
34
|
money = Money.new(100_00, "USD")
|
35
|
-
money.bank.should_receive(:exchange).with(100_00, "USD", "EUR").and_return(200_00)
|
35
|
+
money.bank.should_receive(:exchange).with(100_00, Money::Currency.new("USD"), Money::Currency.new("EUR")).and_return(200_00)
|
36
36
|
money.exchange_to("EUR")
|
37
37
|
end
|
38
38
|
|
39
39
|
specify "#exchange_to exchanges the amount properly" do
|
40
40
|
money = Money.new(100_00, "USD")
|
41
|
-
money.bank.should_receive(:exchange).with(100_00, "USD", "EUR").and_return(200_00)
|
41
|
+
money.bank.should_receive(:exchange).with(100_00, Money::Currency.new("USD"), Money::Currency.new("EUR")).and_return(200_00)
|
42
42
|
money.exchange_to("EUR").should == Money.new(200_00, "EUR")
|
43
43
|
end
|
44
44
|
|
@@ -149,7 +149,7 @@ describe Money do
|
|
149
149
|
|
150
150
|
specify "Money.new accepts { :currency => 'foo' } as the value for the 'currency' argument" do
|
151
151
|
money = Money.new(20, :currency => "EUR")
|
152
|
-
money.currency.should == "EUR"
|
152
|
+
money.currency.should == Money::Currency.new("EUR")
|
153
153
|
|
154
154
|
money = Money.new(20, :currency => nil)
|
155
155
|
money.currency.should == Money.default_currency
|
@@ -186,7 +186,7 @@ describe Money do
|
|
186
186
|
one_thousand["CAD"].should == "$1,000.00"
|
187
187
|
one_thousand["AUD"].should == "$1,000.00"
|
188
188
|
one_thousand["NZD"].should == "$1,000.00"
|
189
|
-
one_thousand["ZWD"].should == "
|
189
|
+
one_thousand["ZWD"].should == "$1,000.00"
|
190
190
|
|
191
191
|
# Yen
|
192
192
|
one_thousand["JPY"].should == "¥1,000.00"
|
@@ -206,7 +206,7 @@ describe Money do
|
|
206
206
|
|
207
207
|
# Other
|
208
208
|
one_thousand["SEK"].should == "kr1,000.00"
|
209
|
-
one_thousand["GHC"].should == "
|
209
|
+
one_thousand["GHC"].should == "₵1,000.00"
|
210
210
|
end
|
211
211
|
|
212
212
|
describe "if the monetary value is 0" do
|
@@ -228,7 +228,50 @@ describe Money do
|
|
228
228
|
@money.format(:display_free => 'gratis').should == 'gratis'
|
229
229
|
end
|
230
230
|
end
|
231
|
+
|
232
|
+
|
233
|
+
specify "#symbol works as documented" do
|
234
|
+
currency = Money::Currency.new("EUR")
|
235
|
+
currency.should_receive(:symbol).and_return("€")
|
236
|
+
Money.empty(currency).symbol.should == "€"
|
237
|
+
|
238
|
+
currency = Money::Currency.new("EUR")
|
239
|
+
currency.should_receive(:symbol).and_return(nil)
|
240
|
+
Money.empty(currency).symbol.should == "$"
|
241
|
+
end
|
242
|
+
|
243
|
+
specify "#delimiter works as documented" do
|
244
|
+
begin
|
245
|
+
old = Money::DELIMITERS.dup
|
246
|
+
Money::DELIMITERS.clear
|
247
|
+
Money::DELIMITERS["EUR"] = "."
|
248
|
+
|
249
|
+
Money.empty("EUR").delimiter.should == "."
|
250
|
+
Money.empty("USD").delimiter.should == ","
|
251
|
+
Money.empty("GBP").delimiter.should == ","
|
252
|
+
ensure
|
253
|
+
silence_warnings do
|
254
|
+
Money::DELIMITERS = old
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
231
258
|
|
259
|
+
specify "#separator works as documented" do
|
260
|
+
begin
|
261
|
+
old = Money::SEPARATORS.dup
|
262
|
+
Money::SEPARATORS.clear
|
263
|
+
Money::SEPARATORS["EUR"] = "_"
|
264
|
+
|
265
|
+
Money.empty("EUR").separator.should == "_"
|
266
|
+
Money.empty("USD").separator.should == "."
|
267
|
+
Money.empty("GBP").separator.should == "."
|
268
|
+
ensure
|
269
|
+
silence_warnings do
|
270
|
+
Money::SEPARATORS = old
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
232
275
|
specify "#format(:with_currency => true) works as documented" do
|
233
276
|
Money.ca_dollar(100).format(:with_currency => true).should == "$1.00 CAD"
|
234
277
|
Money.us_dollar(85).format(:with_currency => true).should == "$0.85 USD"
|
@@ -271,7 +314,7 @@ describe Money do
|
|
271
314
|
one["CAD"].should == "$1.00"
|
272
315
|
one["AUD"].should == "$1.00"
|
273
316
|
one["NZD"].should == "$1.00"
|
274
|
-
one["ZWD"].should == "
|
317
|
+
one["ZWD"].should == "$1.00"
|
275
318
|
|
276
319
|
# Yen
|
277
320
|
one["JPY"].should == "¥1.00"
|
@@ -291,11 +334,13 @@ describe Money do
|
|
291
334
|
|
292
335
|
# Other
|
293
336
|
one["SEK"].should == "kr1.00"
|
294
|
-
one["GHC"].should == "
|
337
|
+
one["GHC"].should == "₵1.00"
|
295
338
|
end
|
296
339
|
|
297
340
|
specify "#format(:symbol => true) returns $ when currency code is not recognized" do
|
298
|
-
Money.new(
|
341
|
+
currency = Money::Currency.new("EUR")
|
342
|
+
currency.should_receive(:symbol).and_return(nil)
|
343
|
+
Money.new(100, currency).format(:symbol => true).should == "$1.00"
|
299
344
|
end
|
300
345
|
|
301
346
|
specify "#format(:symbol => some non-Boolean value that evaluates to true) returs symbol based on the given currency code" do
|
@@ -318,8 +363,8 @@ describe Money do
|
|
318
363
|
money = Money.new(100, "GBP")
|
319
364
|
money.format.should == "£1.00"
|
320
365
|
|
321
|
-
money = Money.new(100, "
|
322
|
-
money.format.should == "
|
366
|
+
money = Money.new(100, "EUR")
|
367
|
+
money.format.should == "€1.00"
|
323
368
|
end
|
324
369
|
|
325
370
|
specify "#format(:separator => a separator string) works as documented" do
|
@@ -327,7 +372,7 @@ describe Money do
|
|
327
372
|
end
|
328
373
|
|
329
374
|
specify "#format will default separator to '.' if currency isn't recognized" do
|
330
|
-
Money.new(100, "
|
375
|
+
Money.new(100, "ZWD").format.should == "$1.00"
|
331
376
|
end
|
332
377
|
|
333
378
|
specify "#format(:delimiter => a delimiter string) works as documented" do
|
@@ -341,7 +386,7 @@ describe Money do
|
|
341
386
|
end
|
342
387
|
|
343
388
|
specify "#format will default delimiter to ',' if currency isn't recognized" do
|
344
|
-
Money.new(100000, "
|
389
|
+
Money.new(100000, "ZWD").format.should == "$1,000.00"
|
345
390
|
end
|
346
391
|
|
347
392
|
specify "#format(:html => true) works as documented" do
|
@@ -354,6 +399,22 @@ describe Money do
|
|
354
399
|
Money.us_dollar(1_000_000_000_12).format(:no_cents => true).should == "$1,000,000,000"
|
355
400
|
end
|
356
401
|
end
|
402
|
+
|
403
|
+
|
404
|
+
# Sets $VERBOSE to nil for the duration of the block and back to its original value afterwards.
|
405
|
+
#
|
406
|
+
# silence_warnings do
|
407
|
+
# value = noisy_call # no warning voiced
|
408
|
+
# end
|
409
|
+
#
|
410
|
+
# noisy_call # warning voiced
|
411
|
+
def silence_warnings
|
412
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
413
|
+
yield
|
414
|
+
ensure
|
415
|
+
$VERBOSE = old_verbose
|
416
|
+
end
|
417
|
+
|
357
418
|
end
|
358
419
|
|
359
420
|
describe "Actions involving two Money objects" do
|
@@ -380,33 +441,33 @@ describe "Actions involving two Money objects" do
|
|
380
441
|
describe "if the other Money object has a different currency" do
|
381
442
|
specify "#<=> compares the two objects' amount after converting the other object's amount to its own currency" do
|
382
443
|
target = Money.new(200_00, "EUR")
|
383
|
-
target.should_receive(:exchange_to).with("USD").and_return(Money.new(300_00, "USD"))
|
444
|
+
target.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(300_00, "USD"))
|
384
445
|
(Money.new(100_00, "USD") <=> target).should < 0
|
385
446
|
|
386
447
|
target = Money.new(200_00, "EUR")
|
387
|
-
target.should_receive(:exchange_to).with("USD").and_return(Money.new(100_00, "USD"))
|
448
|
+
target.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(100_00, "USD"))
|
388
449
|
(Money.new(100_00, "USD") <=> target).should == 0
|
389
450
|
|
390
451
|
target = Money.new(200_00, "EUR")
|
391
|
-
target.should_receive(:exchange_to).with("USD").and_return(Money.new(99_00, "USD"))
|
452
|
+
target.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(99_00, "USD"))
|
392
453
|
(Money.new(100_00, "USD") <=> target).should > 0
|
393
454
|
end
|
394
455
|
|
395
456
|
specify "#+ adds the other object's amount, converted to this object's currency, to this object's amount while retaining its currency" do
|
396
457
|
other = Money.new(90, "EUR")
|
397
|
-
other.should_receive(:exchange_to).with("USD").and_return(Money.new(9_00, "USD"))
|
458
|
+
other.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(9_00, "USD"))
|
398
459
|
(Money.new(10_00, "USD") + other).should == Money.new(19_00, "USD")
|
399
460
|
end
|
400
461
|
|
401
462
|
specify "#- substracts the other object's amount, converted to this object's currency, from this object's amount while retaining its currency" do
|
402
463
|
other = Money.new(90, "EUR")
|
403
|
-
other.should_receive(:exchange_to).with("USD").and_return(Money.new(9_00, "USD"))
|
464
|
+
other.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(9_00, "USD"))
|
404
465
|
(Money.new(10_00, "USD") - other).should == Money.new(1_00, "USD")
|
405
466
|
end
|
406
467
|
|
407
468
|
specify "#/ divides the this object's amount by the other objects's amount, converted to this object's currency, resulting in a float" do
|
408
469
|
other = Money.new(1000, "EUR")
|
409
|
-
other.should_receive(:exchange_to).with("USD").and_return(Money.new(100_00, "USD"))
|
470
|
+
other.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(100_00, "USD"))
|
410
471
|
(Money.new(10_00, "USD") / other).should == 0.1
|
411
472
|
end
|
412
473
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 2
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 2.3.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Tobias Luetke
|
@@ -12,29 +17,37 @@ autorequire:
|
|
12
17
|
bindir: bin
|
13
18
|
cert_chain: []
|
14
19
|
|
15
|
-
date: 2010-
|
20
|
+
date: 2010-04-16 00:00:00 -04:00
|
16
21
|
default_executable:
|
17
22
|
dependencies:
|
18
23
|
- !ruby/object:Gem::Dependency
|
19
24
|
name: rspec
|
20
|
-
|
21
|
-
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
27
|
requirements:
|
24
28
|
- - ">="
|
25
29
|
- !ruby/object:Gem::Version
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
26
34
|
version: 1.2.9
|
27
|
-
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
28
37
|
- !ruby/object:Gem::Dependency
|
29
38
|
name: hanna
|
30
|
-
|
31
|
-
|
32
|
-
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
33
41
|
requirements:
|
34
42
|
- - ">="
|
35
43
|
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 1
|
47
|
+
- 12
|
36
48
|
version: 0.1.12
|
37
|
-
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
38
51
|
description: Money and currency exchange support library.
|
39
52
|
email: hongli@phusion.nl
|
40
53
|
executables: []
|
@@ -42,23 +55,27 @@ executables: []
|
|
42
55
|
extensions: []
|
43
56
|
|
44
57
|
extra_rdoc_files:
|
58
|
+
- CHANGELOG.rdoc
|
45
59
|
- LICENSE
|
46
60
|
- README.rdoc
|
47
61
|
files:
|
48
62
|
- .document
|
49
63
|
- .gitignore
|
64
|
+
- CHANGELOG.rdoc
|
50
65
|
- LICENSE
|
51
66
|
- README.rdoc
|
52
67
|
- Rakefile
|
53
68
|
- VERSION
|
54
69
|
- lib/money.rb
|
55
70
|
- lib/money/core_extensions.rb
|
71
|
+
- lib/money/currency.rb
|
56
72
|
- lib/money/defaults.rb
|
57
73
|
- lib/money/errors.rb
|
58
74
|
- lib/money/money.rb
|
59
75
|
- lib/money/variable_exchange_bank.rb
|
60
76
|
- money.gemspec
|
61
77
|
- test/core_extensions_spec.rb
|
78
|
+
- test/currency_spec.rb
|
62
79
|
- test/exchange_bank_spec.rb
|
63
80
|
- test/money_spec.rb
|
64
81
|
has_rdoc: true
|
@@ -74,22 +91,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
91
|
requirements:
|
75
92
|
- - ">="
|
76
93
|
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 0
|
77
96
|
version: "0"
|
78
|
-
version:
|
79
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
98
|
requirements:
|
81
99
|
- - ">="
|
82
100
|
- !ruby/object:Gem::Version
|
101
|
+
segments:
|
102
|
+
- 0
|
83
103
|
version: "0"
|
84
|
-
version:
|
85
104
|
requirements: []
|
86
105
|
|
87
106
|
rubyforge_project: money
|
88
|
-
rubygems_version: 1.3.
|
107
|
+
rubygems_version: 1.3.6
|
89
108
|
signing_key:
|
90
109
|
specification_version: 3
|
91
110
|
summary: Money and currency exchange support library
|
92
111
|
test_files:
|
93
112
|
- test/core_extensions_spec.rb
|
113
|
+
- test/currency_spec.rb
|
94
114
|
- test/exchange_bank_spec.rb
|
95
115
|
- test/money_spec.rb
|