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
data/money.gemspec
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
Gem::Specification.new do |s|
|
3
|
-
s.name = "money"
|
4
|
-
s.version = "4.0.
|
5
|
-
s.platform = Gem::Platform::RUBY
|
6
|
-
s.authors = ["Tobias Luetke", "Hongli Lai", "Jeremy McNevin",
|
7
|
-
"Shane Emmons", "Simone Carletti"]
|
8
|
-
s.email = ["semmons99+RubyMoney@gmail.com"]
|
9
|
-
s.homepage = "
|
10
|
-
s.summary = "Money and currency exchange support library."
|
11
|
-
s.description = "This library aids one in handling money and different currencies."
|
12
|
-
|
13
|
-
s.required_rubygems_version = ">= 1.3.6"
|
14
|
-
s.rubyforge_project = "money"
|
15
|
-
|
16
|
-
s.add_dependency "i18n", "~> 0.4"
|
17
|
-
s.add_dependency "json"
|
18
|
-
|
19
|
-
s.add_development_dependency "rspec", "
|
20
|
-
s.add_development_dependency "yard"
|
21
|
-
|
22
|
-
s.requirements << "json"
|
23
|
-
|
24
|
-
s.files = Dir.glob("{config,lib,spec}/**/*")
|
25
|
-
s.files += %w(CHANGELOG.md LICENSE README.md)
|
26
|
-
s.files += %w(Rakefile .gemtest money.gemspec)
|
27
|
-
|
28
|
-
s.require_path = "lib"
|
29
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = "money"
|
4
|
+
s.version = "4.0.2"
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.authors = ["Tobias Luetke", "Hongli Lai", "Jeremy McNevin",
|
7
|
+
"Shane Emmons", "Simone Carletti"]
|
8
|
+
s.email = ["semmons99+RubyMoney@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/RubyMoney/money"
|
10
|
+
s.summary = "Money and currency exchange support library."
|
11
|
+
s.description = "This library aids one in handling money and different currencies."
|
12
|
+
|
13
|
+
s.required_rubygems_version = ">= 1.3.6"
|
14
|
+
s.rubyforge_project = "money"
|
15
|
+
|
16
|
+
s.add_dependency "i18n", "~> 0.4"
|
17
|
+
s.add_dependency "json"
|
18
|
+
|
19
|
+
s.add_development_dependency "rspec", "~> 2.8.0"
|
20
|
+
s.add_development_dependency "yard"
|
21
|
+
|
22
|
+
s.requirements << "json"
|
23
|
+
|
24
|
+
s.files = Dir.glob("{config,lib,spec}/**/*")
|
25
|
+
s.files += %w(CHANGELOG.md LICENSE README.md)
|
26
|
+
s.files += %w(Rakefile .gemtest money.gemspec)
|
27
|
+
|
28
|
+
s.require_path = "lib"
|
29
|
+
end
|
data/spec/bank/base_spec.rb
CHANGED
@@ -1,72 +1,69 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
describe Money::Bank::Base do
|
4
|
-
|
5
|
-
|
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
|
-
end
|
71
|
-
end
|
72
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Money::Bank::Base do
|
4
|
+
|
5
|
+
describe "#initialize" do
|
6
|
+
it "accepts a block and stores @rounding_method" do
|
7
|
+
proc = Proc.new { |n| n.ceil }
|
8
|
+
bank = Money::Bank::Base.new(&proc)
|
9
|
+
bank.rounding_method.should == proc
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#setup" do
|
14
|
+
it "calls #setup after #initialize" do
|
15
|
+
class MyBank < Money::Bank::Base
|
16
|
+
attr_reader :setup_called
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@setup_called = true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
bank = MyBank.new
|
24
|
+
bank.setup_called.should == true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#exchange_with" do
|
29
|
+
it "is not implemented" do
|
30
|
+
expect { subject.exchange_with(Money.new(100, 'USD'), 'EUR') }.to raise_exception(NotImplementedError)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#same_currency?" do
|
35
|
+
it "accepts str/str" do
|
36
|
+
expect { subject.send(:same_currency?, 'USD', 'EUR') }.to_not raise_exception
|
37
|
+
end
|
38
|
+
|
39
|
+
it "accepts currency/str" do
|
40
|
+
expect { subject.send(:same_currency?, Money::Currency.wrap('USD'), 'EUR') }.to_not raise_exception
|
41
|
+
end
|
42
|
+
|
43
|
+
it "accepts str/currency" do
|
44
|
+
expect { subject.send(:same_currency?, 'USD', Money::Currency.wrap('EUR')) }.to_not raise_exception
|
45
|
+
end
|
46
|
+
|
47
|
+
it "accepts currency/currency" do
|
48
|
+
expect { subject.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR')) }.to_not raise_exception
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns true when currencies match" do
|
52
|
+
subject.send(:same_currency?, 'USD', 'USD').should be_true
|
53
|
+
subject.send(:same_currency?, Money::Currency.wrap('USD'), 'USD').should be_true
|
54
|
+
subject.send(:same_currency?, 'USD', Money::Currency.wrap('USD')).should be_true
|
55
|
+
subject.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('USD')).should be_true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns false when currencies do not match" do
|
59
|
+
subject.send(:same_currency?, 'USD', 'EUR').should be_false
|
60
|
+
subject.send(:same_currency?, Money::Currency.wrap('USD'), 'EUR').should be_false
|
61
|
+
subject.send(:same_currency?, 'USD', Money::Currency.wrap('EUR')).should be_false
|
62
|
+
subject.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR')).should be_false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "raises an UnknownCurrency exception when an unknown currency is passed" do
|
66
|
+
expect { subject.send(:same_currency?, 'AAA', 'BBB') }.to raise_exception(Money::Currency::UnknownCurrency)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,238 +1,233 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
5
|
-
describe Money::Bank::VariableExchange do
|
6
|
-
|
7
|
-
describe
|
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
|
-
end
|
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
|
-
|
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
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
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
|
-
b.rates.should == @bank.rates
|
235
|
-
b.rounding_method.should == @bank.rounding_method
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
describe Money::Bank::VariableExchange do
|
6
|
+
|
7
|
+
describe "#initialize" do
|
8
|
+
context "without &block" do
|
9
|
+
let(:bank) {
|
10
|
+
Money::Bank::VariableExchange.new.tap do |bank|
|
11
|
+
bank.add_rate('USD', 'EUR', 1.33)
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
describe "#exchange_with" do
|
16
|
+
it "accepts str" do
|
17
|
+
expect { bank.exchange_with(Money.new(100, 'USD'), 'EUR') }.to_not raise_exception
|
18
|
+
end
|
19
|
+
|
20
|
+
it "accepts currency" do
|
21
|
+
expect { bank.exchange_with(Money.new(100, 'USD'), Money::Currency.wrap('EUR')) }.to_not raise_exception
|
22
|
+
end
|
23
|
+
|
24
|
+
it "exchanges one currency to another" do
|
25
|
+
bank.exchange_with(Money.new(100, 'USD'), 'EUR').should == Money.new(133, 'EUR')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "truncates extra digits" do
|
29
|
+
bank.exchange_with(Money.new(10, 'USD'), 'EUR').should == Money.new(13, 'EUR')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises an UnknownCurrency exception when an unknown currency is requested" do
|
33
|
+
expect { bank.exchange_with(Money.new(100, 'USD'), 'BBB') }.to raise_exception(Money::Currency::UnknownCurrency)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises an UnknownRate exception when an unknown rate is requested" do
|
37
|
+
expect { bank.exchange_with(Money.new(100, 'USD'), 'JPY') }.to raise_exception(Money::Bank::UnknownRate)
|
38
|
+
end
|
39
|
+
|
40
|
+
#it "rounds the exchanged result down" do
|
41
|
+
# bank.add_rate("USD", "EUR", 0.788332676)
|
42
|
+
# bank.add_rate("EUR", "YEN", 122.631477)
|
43
|
+
# bank.exchange_with(Money.new(10_00, "USD"), "EUR").should == Money.new(788, "EUR")
|
44
|
+
# bank.exchange_with(Money.new(500_00, "EUR"), "YEN").should == Money.new(6131573, "YEN")
|
45
|
+
#end
|
46
|
+
|
47
|
+
it "accepts a custom truncation method" do
|
48
|
+
proc = Proc.new { |n| n.ceil }
|
49
|
+
bank.exchange_with(Money.new(10, 'USD'), 'EUR', &proc).should == Money.new(14, 'EUR')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with &block" do
|
55
|
+
let(:bank) {
|
56
|
+
proc = Proc.new { |n| n.ceil }
|
57
|
+
Money::Bank::VariableExchange.new(&proc).tap do |bank|
|
58
|
+
bank.add_rate('USD', 'EUR', 1.33)
|
59
|
+
end
|
60
|
+
}
|
61
|
+
|
62
|
+
describe "#exchange_with" do
|
63
|
+
it "uses the stored truncation method" do
|
64
|
+
bank.exchange_with(Money.new(10, 'USD'), 'EUR').should == Money.new(14, 'EUR')
|
65
|
+
end
|
66
|
+
|
67
|
+
it "accepts a custom truncation method" do
|
68
|
+
proc = Proc.new { |n| n.ceil + 1 }
|
69
|
+
bank.exchange_with(Money.new(10, 'USD'), 'EUR', &proc).should == Money.new(15, 'EUR')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#add_rate" do
|
76
|
+
it "adds rates correctly" do
|
77
|
+
subject.add_rate("USD", "EUR", 0.788332676)
|
78
|
+
subject.add_rate("EUR", "YEN", 122.631477)
|
79
|
+
|
80
|
+
subject.instance_variable_get(:@rates)['USD_TO_EUR'].should == 0.788332676
|
81
|
+
subject.instance_variable_get(:@rates)['EUR_TO_JPY'].should == 122.631477
|
82
|
+
end
|
83
|
+
|
84
|
+
it "treats currency names case-insensitively" do
|
85
|
+
subject.add_rate("usd", "eur", 1)
|
86
|
+
subject.instance_variable_get(:@rates)['USD_TO_EUR'].should == 1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#set_rate" do
|
91
|
+
it "sets a rate" do
|
92
|
+
subject.set_rate('USD', 'EUR', 1.25)
|
93
|
+
subject.instance_variable_get(:@rates)['USD_TO_EUR'].should == 1.25
|
94
|
+
end
|
95
|
+
|
96
|
+
it "raises an UnknownCurrency exception when an unknown currency is passed" do
|
97
|
+
expect { subject.set_rate('AAA', 'BBB', 1.25) }.to raise_exception(Money::Currency::UnknownCurrency)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#get_rate" do
|
102
|
+
it "returns a rate" do
|
103
|
+
subject.set_rate('USD', 'EUR', 1.25)
|
104
|
+
subject.get_rate('USD', 'EUR').should == 1.25
|
105
|
+
end
|
106
|
+
|
107
|
+
it "raises an UnknownCurrency exception when an unknown currency is passed" do
|
108
|
+
expect { subject.get_rate('AAA', 'BBB') }.to raise_exception(Money::Currency::UnknownCurrency)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#export_rates" do
|
113
|
+
before :each do
|
114
|
+
subject.set_rate('USD', 'EUR', 1.25)
|
115
|
+
subject.set_rate('USD', 'JPY', 2.55)
|
116
|
+
|
117
|
+
@rates = { "USD_TO_EUR" => 1.25, "USD_TO_JPY" => 2.55 }
|
118
|
+
end
|
119
|
+
|
120
|
+
context "with format == :json" do
|
121
|
+
it "should return rates formatted as json" do
|
122
|
+
json = subject.export_rates(:json)
|
123
|
+
JSON.load(json).should == @rates
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "with format == :ruby" do
|
128
|
+
it "should return rates formatted as ruby objects" do
|
129
|
+
Marshal.load(subject.export_rates(:ruby)).should == @rates
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with format == :yaml" do
|
134
|
+
it "should return rates formatted as yaml" do
|
135
|
+
yaml = subject.export_rates(:yaml)
|
136
|
+
YAML.load(yaml).should == @rates
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "with unknown format" do
|
141
|
+
it "raises Money::Bank::UnknownRateFormat" do
|
142
|
+
expect { subject.export_rates(:foo)}.should raise_error Money::Bank::UnknownRateFormat
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "with :file provided" do
|
147
|
+
it "writes rates to file" do
|
148
|
+
f = mock('IO')
|
149
|
+
File.should_receive(:open).with('null', 'w').and_return(f)
|
150
|
+
f.should_receive(:write).with(@rates.to_json)
|
151
|
+
|
152
|
+
subject.export_rates(:json, 'null')
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "#import_rates" do
|
158
|
+
context "with format == :json" do
|
159
|
+
it "loads the rates provided" do
|
160
|
+
s = '{"USD_TO_EUR":1.25,"USD_TO_JPY":2.55}'
|
161
|
+
subject.import_rates(:json, s)
|
162
|
+
subject.get_rate('USD', 'EUR').should == 1.25
|
163
|
+
subject.get_rate('USD', 'JPY').should == 2.55
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "with format == :ruby" do
|
168
|
+
it "loads the rates provided" do
|
169
|
+
s = Marshal.dump({"USD_TO_EUR"=>1.25,"USD_TO_JPY"=>2.55})
|
170
|
+
subject.import_rates(:ruby, s)
|
171
|
+
subject.get_rate('USD', 'EUR').should == 1.25
|
172
|
+
subject.get_rate('USD', 'JPY').should == 2.55
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "with format == :yaml" do
|
177
|
+
it "loads the rates provided" do
|
178
|
+
s = "--- \nUSD_TO_EUR: 1.25\nUSD_TO_JPY: 2.55\n"
|
179
|
+
subject.import_rates(:yaml, s)
|
180
|
+
subject.get_rate('USD', 'EUR').should == 1.25
|
181
|
+
subject.get_rate('USD', 'JPY').should == 2.55
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "with unknown format" do
|
186
|
+
it "raises Money::Bank::UnknownRateFormat" do
|
187
|
+
expect { subject.import_rates(:foo, "")}.should raise_error Money::Bank::UnknownRateFormat
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "#rate_key_for" do
|
193
|
+
it "accepts str/str" do
|
194
|
+
expect { subject.send(:rate_key_for, 'USD', 'EUR')}.to_not raise_exception
|
195
|
+
end
|
196
|
+
|
197
|
+
it "accepts currency/str" do
|
198
|
+
expect { subject.send(:rate_key_for, Money::Currency.wrap('USD'), 'EUR')}.to_not raise_exception
|
199
|
+
end
|
200
|
+
|
201
|
+
it "accepts str/currency" do
|
202
|
+
expect { subject.send(:rate_key_for, 'USD', Money::Currency.wrap('EUR'))}.to_not raise_exception
|
203
|
+
end
|
204
|
+
|
205
|
+
it "accepts currency/currency" do
|
206
|
+
expect { subject.send(:rate_key_for, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR'))}.to_not raise_exception
|
207
|
+
end
|
208
|
+
|
209
|
+
it "returns a hashkey based on the passed arguments" do
|
210
|
+
subject.send(:rate_key_for, 'USD', 'EUR').should == 'USD_TO_EUR'
|
211
|
+
subject.send(:rate_key_for, Money::Currency.wrap('USD'), 'EUR').should == 'USD_TO_EUR'
|
212
|
+
subject.send(:rate_key_for, 'USD', Money::Currency.wrap('EUR')).should == 'USD_TO_EUR'
|
213
|
+
subject.send(:rate_key_for, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR')).should == 'USD_TO_EUR'
|
214
|
+
end
|
215
|
+
|
216
|
+
it "raises a Money::Currency::UnknownCurrency exception when an unknown currency is passed" do
|
217
|
+
expect { subject.send(:rate_key_for, 'AAA', 'BBB')}.should raise_exception(Money::Currency::UnknownCurrency)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "#marshal_dump" do
|
222
|
+
it "does not raise an error" do
|
223
|
+
expect { Marshal.dump(subject) }.should_not raise_error
|
224
|
+
end
|
225
|
+
|
226
|
+
it "works with Marshal.load" do
|
227
|
+
bank = Marshal.load(Marshal.dump(subject))
|
228
|
+
|
229
|
+
bank.rates.should == subject.rates
|
230
|
+
bank.rounding_method.should == subject.rounding_method
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|