money 4.0.1 → 4.0.2
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.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,158 +1,160 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe
|
4
|
-
|
5
|
-
describe Numeric do
|
6
|
-
describe "#to_money" do
|
7
|
-
it "
|
8
|
-
money = 1234.to_money
|
9
|
-
money.cents.should == 1234_00
|
10
|
-
money.currency.should == Money.default_currency
|
11
|
-
|
12
|
-
money = 100.37.to_money
|
13
|
-
money.cents.should == 100_37
|
14
|
-
money.currency.should == Money.default_currency
|
15
|
-
|
16
|
-
money = BigDecimal.new('1234').to_money
|
17
|
-
money.cents.should == 1234_00
|
18
|
-
money.currency.should == Money.default_currency
|
19
|
-
end
|
20
|
-
|
21
|
-
it "
|
22
|
-
1234.to_money('USD').should == Money.new(123400, 'USD')
|
23
|
-
1234.to_money('EUR').should == Money.new(123400, 'EUR')
|
24
|
-
end
|
25
|
-
|
26
|
-
it "
|
27
|
-
10.to_money('USD').should == Money.new(10_00, 'USD')
|
28
|
-
10.to_money('TND').should == Money.new(10_000, 'TND')
|
29
|
-
10.to_money('CLP').should == Money.new(10, 'CLP')
|
30
|
-
end
|
31
|
-
|
32
|
-
specify "
|
33
|
-
amount = 555.55.to_money
|
34
|
-
amount.should == Money.new(55555)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe String do
|
40
|
-
describe "#to_money" do
|
41
|
-
|
42
|
-
|
43
|
-
"20.15" => Money.new(20_15) ,
|
44
|
-
"100" => Money.new(100_00) ,
|
45
|
-
"100.37" => Money.new(100_37) ,
|
46
|
-
"100,37" => Money.new(100_37) ,
|
47
|
-
"100 000" => Money.new(100_000_00) ,
|
48
|
-
"100,000.00" => Money.new(100_000_00) ,
|
49
|
-
"1,000" => Money.new(1_000_00) ,
|
50
|
-
"-1,000" => Money.new(-1_000_00) ,
|
51
|
-
"1,000.5" => Money.new(1_000_50) ,
|
52
|
-
"1,000.51" => Money.new(1_000_51) ,
|
53
|
-
"1,000.505" => Money.new(1_000_51) ,
|
54
|
-
"1,000.504" => Money.new(1_000_50) ,
|
55
|
-
"1,000.0000" => Money.new(1_000_00) ,
|
56
|
-
"1,000.5000" => Money.new(1_000_50) ,
|
57
|
-
"1,000.5099" => Money.new(1_000_51) ,
|
58
|
-
"1.550" => Money.new(1_55) ,
|
59
|
-
"25." => Money.new(25_00) ,
|
60
|
-
".75" => Money.new(75) ,
|
61
|
-
|
62
|
-
"100 USD" => Money.new(100_00, "USD") ,
|
63
|
-
"-100 USD" => Money.new(-100_00, "USD") ,
|
64
|
-
"100 EUR" => Money.new(100_00, "EUR") ,
|
65
|
-
"100.37 EUR" => Money.new(100_37, "EUR") ,
|
66
|
-
"100,37 EUR" => Money.new(100_37, "EUR") ,
|
67
|
-
"100,000.00 USD" => Money.new(100_000_00, "USD") ,
|
68
|
-
"100.000,00 EUR" => Money.new(100_000_00, "EUR") ,
|
69
|
-
"1,000 USD" => Money.new(1_000_00, "USD") ,
|
70
|
-
"-1,000 USD" => Money.new(-1_000_00, "USD") ,
|
71
|
-
"1,000.5500 USD" => Money.new(1_000_55, "USD") ,
|
72
|
-
"-1,000.6500 USD" => Money.new(-1_000_65, "USD") ,
|
73
|
-
"1.550 USD" => Money.new(1_55, "USD") ,
|
74
|
-
|
75
|
-
"USD 100" => Money.new(100_00, "USD") ,
|
76
|
-
"EUR 100" => Money.new(100_00, "EUR") ,
|
77
|
-
"EUR 100.37" => Money.new(100_37, "EUR") ,
|
78
|
-
"CAD -100.37" => Money.new(-100_37, "CAD") ,
|
79
|
-
"EUR 100,37" => Money.new(100_37, "EUR") ,
|
80
|
-
"EUR -100,37" => Money.new(-100_37, "EUR") ,
|
81
|
-
"USD 100,000.00" => Money.new(100_000_00, "USD") ,
|
82
|
-
"EUR 100.000,00" => Money.new(100_000_00, "EUR") ,
|
83
|
-
"USD 1,000" => Money.new(1_000_00, "USD") ,
|
84
|
-
"USD -1,000" => Money.new(-1_000_00, "USD") ,
|
85
|
-
"USD 1,000.9000" => Money.new(1_000_90, "USD") ,
|
86
|
-
"USD -1,000.090" => Money.new(-1_000_09, "USD") ,
|
87
|
-
"USD 1.5500" => Money.new(1_55, "USD") ,
|
88
|
-
|
89
|
-
"$100 USD" => Money.new(100_00, "USD") ,
|
90
|
-
"$1,194.59 USD" => Money.new(1_194_59, "USD") ,
|
91
|
-
"$-1,955 USD" => Money.new(-1_955_00, "USD") ,
|
92
|
-
"$1,194.5900 USD" => Money.new(1_194_59, "USD") ,
|
93
|
-
"$-1,955.000 USD" => Money.new(-1_955_00, "USD") ,
|
94
|
-
"$1.99000 USD" => Money.new(1_99, "USD") ,
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
string.to_money.should == money
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
it "
|
104
|
-
Money.parse(20, "USD").should == Money.new(20_00, "USD")
|
105
|
-
end
|
106
|
-
|
107
|
-
it "
|
108
|
-
"10.10".to_money('USD').should == Money.new(1010, 'USD')
|
109
|
-
"10.10".to_money('EUR').should == Money.new(1010, 'EUR')
|
110
|
-
"10.10 USD".to_money('USD').should == Money.new(1010, 'USD')
|
111
|
-
end
|
112
|
-
|
113
|
-
it "
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
it "
|
118
|
-
"hello 2000 world".to_money.should == Money.new(2000_00)
|
119
|
-
end
|
120
|
-
|
121
|
-
it "
|
122
|
-
"1".to_money("USD").should == Money.new(1_00, "USD")
|
123
|
-
"1".to_money("TND").should == Money.new(1_000, "TND")
|
124
|
-
"1".to_money("CLP").should == Money.new(1, "CLP")
|
125
|
-
"1.5".to_money("KWD").cents.should == 1500
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "#to_currency" do
|
130
|
-
it "
|
131
|
-
"USD".to_currency.should == Money::Currency.new(
|
132
|
-
"EUR".to_currency.should == Money::Currency.new(
|
133
|
-
end
|
134
|
-
|
135
|
-
it "
|
136
|
-
|
137
|
-
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe Symbol do
|
143
|
-
describe "#to_currency" do
|
144
|
-
it "
|
145
|
-
:usd.to_currency.should == Money::Currency.new(
|
146
|
-
:ars.to_currency.should == Money::Currency.new(
|
147
|
-
end
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Money, "core extensions" do
|
4
|
+
|
5
|
+
describe Numeric do
|
6
|
+
describe "#to_money" do
|
7
|
+
it "work as documented" do
|
8
|
+
money = 1234.to_money
|
9
|
+
money.cents.should == 1234_00
|
10
|
+
money.currency.should == Money.default_currency
|
11
|
+
|
12
|
+
money = 100.37.to_money
|
13
|
+
money.cents.should == 100_37
|
14
|
+
money.currency.should == Money.default_currency
|
15
|
+
|
16
|
+
money = BigDecimal.new('1234').to_money
|
17
|
+
money.cents.should == 1234_00
|
18
|
+
money.currency.should == Money.default_currency
|
19
|
+
end
|
20
|
+
|
21
|
+
it "accepts optional currency" do
|
22
|
+
1234.to_money('USD').should == Money.new(123400, 'USD')
|
23
|
+
1234.to_money('EUR').should == Money.new(123400, 'EUR')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "respects :subunit_to_unit currency property" do
|
27
|
+
10.to_money('USD').should == Money.new(10_00, 'USD')
|
28
|
+
10.to_money('TND').should == Money.new(10_000, 'TND')
|
29
|
+
10.to_money('CLP').should == Money.new(10, 'CLP')
|
30
|
+
end
|
31
|
+
|
32
|
+
specify "GH-15" do
|
33
|
+
amount = 555.55.to_money
|
34
|
+
amount.should == Money.new(55555)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe String do
|
40
|
+
describe "#to_money" do
|
41
|
+
|
42
|
+
STRING_TO_MONEY = {
|
43
|
+
"20.15" => Money.new(20_15) ,
|
44
|
+
"100" => Money.new(100_00) ,
|
45
|
+
"100.37" => Money.new(100_37) ,
|
46
|
+
"100,37" => Money.new(100_37) ,
|
47
|
+
"100 000" => Money.new(100_000_00) ,
|
48
|
+
"100,000.00" => Money.new(100_000_00) ,
|
49
|
+
"1,000" => Money.new(1_000_00) ,
|
50
|
+
"-1,000" => Money.new(-1_000_00) ,
|
51
|
+
"1,000.5" => Money.new(1_000_50) ,
|
52
|
+
"1,000.51" => Money.new(1_000_51) ,
|
53
|
+
"1,000.505" => Money.new(1_000_51) ,
|
54
|
+
"1,000.504" => Money.new(1_000_50) ,
|
55
|
+
"1,000.0000" => Money.new(1_000_00) ,
|
56
|
+
"1,000.5000" => Money.new(1_000_50) ,
|
57
|
+
"1,000.5099" => Money.new(1_000_51) ,
|
58
|
+
"1.550" => Money.new(1_55) ,
|
59
|
+
"25." => Money.new(25_00) ,
|
60
|
+
".75" => Money.new(75) ,
|
61
|
+
|
62
|
+
"100 USD" => Money.new(100_00, "USD") ,
|
63
|
+
"-100 USD" => Money.new(-100_00, "USD") ,
|
64
|
+
"100 EUR" => Money.new(100_00, "EUR") ,
|
65
|
+
"100.37 EUR" => Money.new(100_37, "EUR") ,
|
66
|
+
"100,37 EUR" => Money.new(100_37, "EUR") ,
|
67
|
+
"100,000.00 USD" => Money.new(100_000_00, "USD") ,
|
68
|
+
"100.000,00 EUR" => Money.new(100_000_00, "EUR") ,
|
69
|
+
"1,000 USD" => Money.new(1_000_00, "USD") ,
|
70
|
+
"-1,000 USD" => Money.new(-1_000_00, "USD") ,
|
71
|
+
"1,000.5500 USD" => Money.new(1_000_55, "USD") ,
|
72
|
+
"-1,000.6500 USD" => Money.new(-1_000_65, "USD") ,
|
73
|
+
"1.550 USD" => Money.new(1_55, "USD") ,
|
74
|
+
|
75
|
+
"USD 100" => Money.new(100_00, "USD") ,
|
76
|
+
"EUR 100" => Money.new(100_00, "EUR") ,
|
77
|
+
"EUR 100.37" => Money.new(100_37, "EUR") ,
|
78
|
+
"CAD -100.37" => Money.new(-100_37, "CAD") ,
|
79
|
+
"EUR 100,37" => Money.new(100_37, "EUR") ,
|
80
|
+
"EUR -100,37" => Money.new(-100_37, "EUR") ,
|
81
|
+
"USD 100,000.00" => Money.new(100_000_00, "USD") ,
|
82
|
+
"EUR 100.000,00" => Money.new(100_000_00, "EUR") ,
|
83
|
+
"USD 1,000" => Money.new(1_000_00, "USD") ,
|
84
|
+
"USD -1,000" => Money.new(-1_000_00, "USD") ,
|
85
|
+
"USD 1,000.9000" => Money.new(1_000_90, "USD") ,
|
86
|
+
"USD -1,000.090" => Money.new(-1_000_09, "USD") ,
|
87
|
+
"USD 1.5500" => Money.new(1_55, "USD") ,
|
88
|
+
|
89
|
+
"$100 USD" => Money.new(100_00, "USD") ,
|
90
|
+
"$1,194.59 USD" => Money.new(1_194_59, "USD") ,
|
91
|
+
"$-1,955 USD" => Money.new(-1_955_00, "USD") ,
|
92
|
+
"$1,194.5900 USD" => Money.new(1_194_59, "USD") ,
|
93
|
+
"$-1,955.000 USD" => Money.new(-1_955_00, "USD") ,
|
94
|
+
"$1.99000 USD" => Money.new(1_99, "USD") ,
|
95
|
+
}
|
96
|
+
|
97
|
+
it "works as documented" do
|
98
|
+
STRING_TO_MONEY.each do |string, money|
|
99
|
+
string.to_money.should == money
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it "coerces input to string" do
|
104
|
+
Money.parse(20, "USD").should == Money.new(20_00, "USD")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "accepts optional currency" do
|
108
|
+
"10.10".to_money('USD').should == Money.new(1010, 'USD')
|
109
|
+
"10.10".to_money('EUR').should == Money.new(1010, 'EUR')
|
110
|
+
"10.10 USD".to_money('USD').should == Money.new(1010, 'USD')
|
111
|
+
end
|
112
|
+
|
113
|
+
it "raises error if optional currency doesn't match string currency" do
|
114
|
+
expect { "10.10 USD".to_money('EUR') }.to raise_error(/Mismatching Currencies/)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "ignores unrecognized data" do
|
118
|
+
"hello 2000 world".to_money.should == Money.new(2000_00)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "respects :subunit_to_unit currency property" do
|
122
|
+
"1".to_money("USD").should == Money.new(1_00, "USD")
|
123
|
+
"1".to_money("TND").should == Money.new(1_000, "TND")
|
124
|
+
"1".to_money("CLP").should == Money.new(1, "CLP")
|
125
|
+
"1.5".to_money("KWD").cents.should == 1500
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#to_currency" do
|
130
|
+
it "converts String to Currency" do
|
131
|
+
"USD".to_currency.should == Money::Currency.new("USD")
|
132
|
+
"EUR".to_currency.should == Money::Currency.new("EUR")
|
133
|
+
end
|
134
|
+
|
135
|
+
it "raises Money::Currency::UnknownCurrency with unknown Currency" do
|
136
|
+
expect { "XXX".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
|
137
|
+
expect { " ".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe Symbol do
|
143
|
+
describe "#to_currency" do
|
144
|
+
it "converts Symbol to Currency" do
|
145
|
+
:usd.to_currency.should == Money::Currency.new("USD")
|
146
|
+
:ars.to_currency.should == Money::Currency.new("ARS")
|
147
|
+
end
|
148
|
+
|
149
|
+
it "is case-insensitive" do
|
150
|
+
:EUR.to_currency.should == Money::Currency.new("EUR")
|
151
|
+
end
|
152
|
+
|
153
|
+
it "raises Money::Currency::UnknownCurrency with unknown Currency" do
|
154
|
+
expect { :XXX.to_currency }.to raise_error(Money::Currency::UnknownCurrency)
|
155
|
+
expect { :" ".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
data/spec/currency_spec.rb
CHANGED
@@ -1,120 +1,139 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe Money::Currency 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
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
Money::Currency.
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
#
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Money::Currency do
|
6
|
+
|
7
|
+
describe ".find" do
|
8
|
+
it "returns currency matching given id" do
|
9
|
+
with_custom_definitions do
|
10
|
+
Money::Currency::TABLE[:usd] = JSON.parse(%Q({ "priority": 1, "iso_code": "USD", "iso_numeric": "840", "name": "United States Dollar", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 100, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": "," }))
|
11
|
+
Money::Currency::TABLE[:eur] = JSON.parse(%Q({ "priority": 2, "iso_code": "EUR", "iso_numeric": "978", "name": "Euro", "symbol": "€", "subunit": "Cent", "subunit_to_unit": 100, "symbol_first": false, "html_entity": "€", "decimal_mark": ",", "thousands_separator": "." }))
|
12
|
+
|
13
|
+
expected = Money::Currency.new(:eur)
|
14
|
+
Money::Currency.find(:eur).should == expected
|
15
|
+
Money::Currency.find(:EUR).should == expected
|
16
|
+
Money::Currency.find("eur").should == expected
|
17
|
+
Money::Currency.find("EUR").should == expected
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns nil unless currency matching given id" do
|
22
|
+
Money::Currency.find("ZZZ").should be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ".wrap" do
|
27
|
+
it "returns nil if object is nil" do
|
28
|
+
Money::Currency.wrap(nil).should == nil
|
29
|
+
Money::Currency.wrap(Money::Currency.new(:usd)).should == Money::Currency.new(:usd)
|
30
|
+
Money::Currency.wrap(:usd).should == Money::Currency.new(:usd)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe "#initialize" do
|
36
|
+
it "lookups data from loaded config" do
|
37
|
+
currency = Money::Currency.new("USD")
|
38
|
+
currency.id.should == :usd
|
39
|
+
currency.priority.should == 1
|
40
|
+
currency.iso_code.should == "USD"
|
41
|
+
currency.iso_numeric.should == "840"
|
42
|
+
currency.name.should == "United States Dollar"
|
43
|
+
currency.decimal_mark.should == "."
|
44
|
+
currency.separator.should == "."
|
45
|
+
currency.thousands_separator.should == ","
|
46
|
+
currency.delimiter.should == ","
|
47
|
+
end
|
48
|
+
|
49
|
+
it "raises UnknownMoney::Currency with unknown currency" do
|
50
|
+
lambda { Money::Currency.new("xxx") }.should raise_error(Money::Currency::UnknownCurrency, /xxx/)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#<=>" do
|
55
|
+
it "compares objects by priority" do
|
56
|
+
Money::Currency.new(:cad).should > Money::Currency.new(:usd)
|
57
|
+
Money::Currency.new(:usd).should < Money::Currency.new(:eur)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#==" do
|
62
|
+
it "returns true if self === other" do
|
63
|
+
currency = Money::Currency.new(:eur)
|
64
|
+
currency.should == currency
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns true if the id is equal" do
|
68
|
+
Money::Currency.new(:eur).should == Money::Currency.new(:eur)
|
69
|
+
Money::Currency.new(:eur).should_not == Money::Currency.new(:usd)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#eql?" do
|
74
|
+
it "returns true if #== returns true" do
|
75
|
+
Money::Currency.new(:eur).eql?(Money::Currency.new(:eur)).should be true
|
76
|
+
Money::Currency.new(:eur).eql?(Money::Currency.new(:usd)).should be false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#hash" do
|
81
|
+
it "returns the same value for equal objects" do
|
82
|
+
Money::Currency.new(:eur).hash.should == Money::Currency.new(:eur).hash
|
83
|
+
Money::Currency.new(:eur).hash.should_not == Money::Currency.new(:usd).hash
|
84
|
+
end
|
85
|
+
|
86
|
+
it "can be used to return the intersection of Currency object arrays" do
|
87
|
+
intersection = [Money::Currency.new(:eur), Money::Currency.new(:usd)] & [Money::Currency.new(:eur)]
|
88
|
+
intersection.should == [Money::Currency.new(:eur)]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#inspect" do
|
93
|
+
it "works as documented" do
|
94
|
+
Money::Currency.new(:usd).inspect.should ==
|
95
|
+
%Q{#<Money::Currency id: usd, priority: 1, symbol_first: true, thousands_separator: ,, html_entity: $, decimal_mark: ., name: United States Dollar, symbol: $, subunit_to_unit: 100, iso_code: USD, iso_numeric: 840, subunit: Cent>}
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#to_s" do
|
100
|
+
it "works as documented" do
|
101
|
+
Money::Currency.new(:usd).to_s.should == "USD"
|
102
|
+
Money::Currency.new(:eur).to_s.should == "EUR"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#to_currency" do
|
107
|
+
it "works as documented" do
|
108
|
+
usd = Money::Currency.new(:usd)
|
109
|
+
usd.to_currency.should == usd
|
110
|
+
end
|
111
|
+
|
112
|
+
it "doesn't create new symbols indefinitely" do
|
113
|
+
expect {
|
114
|
+
expect { Money::Currency.new("bogus") }.to raise_exception(Money::Currency::UnknownCurrency)
|
115
|
+
}.to_not change{ Symbol.all_symbols.size }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#code" do
|
120
|
+
it "works as documented" do
|
121
|
+
Money::Currency.new(:usd).code.should == "$"
|
122
|
+
Money::Currency.new(:azn).code.should == "AZN"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def with_custom_definitions(&block)
|
128
|
+
begin
|
129
|
+
old = Money::Currency::TABLE.dup
|
130
|
+
Money::Currency::TABLE.clear
|
131
|
+
yield
|
132
|
+
ensure
|
133
|
+
silence_warnings do
|
134
|
+
Money::Currency.const_set("TABLE", old)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|