money-openexchangerates-bank 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/money/bank/openexchangerates_bank.rb +1 -1
- data/test/openexchangerates_bank_test.rb +27 -27
- metadata +3 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 16a3dbd841e49f62e93f4852aeddd725e57de2e9937421d9593790d5347bfffe
|
4
|
+
data.tar.gz: f400ea59ee1d8ae6b65b5e704b739ec7551897174410ecfbece20da06d4e0bd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da444777a24ae70cf8b9099deb0ae987544bd92fe1609f94901c600598464f6647fb2576ef5acdb9d124427dc027d2b4be839ed5835ae773c82a76273fef111c
|
7
|
+
data.tar.gz: e8e960098d58ac54741000b883adcf112412b20ccbb30ac1ea6a7eca16be862afe6ff4a7564da440e111e9cc3ef09a5a27e0d4974f4314b1efe1f1cca2d94ac6
|
@@ -30,12 +30,12 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
30
30
|
describe 'without rates' do
|
31
31
|
it 'able to exchange a money to its own currency even without rates' do
|
32
32
|
money = Money.new(0, 'USD')
|
33
|
-
subject.exchange_with(money, 'USD').must_equal money
|
33
|
+
_(subject.exchange_with(money, 'USD')).must_equal money
|
34
34
|
end
|
35
35
|
|
36
36
|
it "raise if it can't find an exchange rate" do
|
37
37
|
money = Money.new(0, 'USD')
|
38
|
-
proc { subject.exchange_with(money, 'LTL') }
|
38
|
+
_(proc { subject.exchange_with(money, 'LTL') })
|
39
39
|
.must_raise Money::Bank::UnknownRate
|
40
40
|
end
|
41
41
|
end
|
@@ -47,17 +47,17 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
47
47
|
|
48
48
|
it 'should be able to exchange money from USD to a known exchange rate' do
|
49
49
|
money = Money.new(100, 'USD')
|
50
|
-
subject.exchange_with(money, 'BBD').must_equal Money.new(200, 'BBD')
|
50
|
+
_(subject.exchange_with(money, 'BBD')).must_equal Money.new(200, 'BBD')
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'should be able to exchange money from a known exchange rate to USD' do
|
54
54
|
money = Money.new(200, 'BBD')
|
55
|
-
subject.exchange_with(money, 'USD').must_equal Money.new(100, 'USD')
|
55
|
+
_(subject.exchange_with(money, 'USD')).must_equal Money.new(100, 'USD')
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should raise if it can't find an exchange rate" do
|
59
59
|
money = Money.new(0, 'USD')
|
60
|
-
proc { subject.exchange_with(money, 'LTL') }
|
60
|
+
_(proc { subject.exchange_with(money, 'LTL') })
|
61
61
|
.must_raise Money::Bank::UnknownRate
|
62
62
|
end
|
63
63
|
end
|
@@ -87,21 +87,21 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
87
87
|
initial_size = File.read(temp_cache_path).size
|
88
88
|
stub(subject).open_url { '' }
|
89
89
|
subject.update_rates
|
90
|
-
File.read(temp_cache_path).size.must_equal initial_size
|
90
|
+
_(File.read(temp_cache_path).size).must_equal initial_size
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'should not break an existing file if save returns json without rates' do
|
94
94
|
initial_size = File.read(temp_cache_path).size
|
95
95
|
stub(subject).open_url { '{ "error": "An error" }' }
|
96
96
|
subject.update_rates
|
97
|
-
File.read(temp_cache_path).size.must_equal initial_size
|
97
|
+
_(File.read(temp_cache_path).size).must_equal initial_size
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should not break an existing file if save returns a invalid json' do
|
101
101
|
initial_size = File.read(temp_cache_path).size
|
102
102
|
stub(subject).open_url { '{ invalid_json: "An error" }' }
|
103
103
|
subject.update_rates
|
104
|
-
File.read(temp_cache_path).size.must_equal initial_size
|
104
|
+
_(File.read(temp_cache_path).size).must_equal initial_size
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -114,7 +114,7 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
114
114
|
|
115
115
|
it 'should get from url' do
|
116
116
|
subject.update_rates
|
117
|
-
subject.rates.wont_be_empty
|
117
|
+
_(subject.rates).wont_be_empty
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -126,7 +126,7 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'should raise an error if invalid path is given' do
|
129
|
-
proc { subject.update_rates }.must_raise Money::Bank::InvalidCache
|
129
|
+
_(proc { subject.update_rates }).must_raise Money::Bank::InvalidCache
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
@@ -146,16 +146,16 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
146
146
|
it 'should get from url normally' do
|
147
147
|
stub(subject).source_url { data_path }
|
148
148
|
subject.update_rates
|
149
|
-
subject.rates.wont_be_empty
|
149
|
+
_(subject.rates).wont_be_empty
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'should save from url and get from cache' do
|
153
153
|
stub(subject).source_url { data_path }
|
154
154
|
subject.update_rates
|
155
|
-
@global_rates.wont_be_empty
|
155
|
+
_(@global_rates).wont_be_empty
|
156
156
|
dont_allow(subject).source_url
|
157
157
|
subject.update_rates
|
158
|
-
subject.rates.wont_be_empty
|
158
|
+
_(subject.rates).wont_be_empty
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
@@ -163,7 +163,7 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
163
163
|
it "should use the non-secure http url if secure_connection isn't set" do
|
164
164
|
subject.secure_connection = nil
|
165
165
|
subject.access_key = TEST_ACCESS_KEY
|
166
|
-
subject.source_url.must_equal "#{url}?base=#{source}&"\
|
166
|
+
_(subject.source_url).must_equal "#{url}?base=#{source}&"\
|
167
167
|
"app_id=#{TEST_ACCESS_KEY}&"\
|
168
168
|
'prettyprint=0'
|
169
169
|
end
|
@@ -171,7 +171,7 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
171
171
|
it 'should use the non-secure http url if secure_connection is false' do
|
172
172
|
subject.secure_connection = false
|
173
173
|
subject.access_key = TEST_ACCESS_KEY
|
174
|
-
subject.source_url.must_equal "#{url}?base=#{source}&"\
|
174
|
+
_(subject.source_url).must_equal "#{url}?base=#{source}&"\
|
175
175
|
"app_id=#{TEST_ACCESS_KEY}&"\
|
176
176
|
'prettyprint=0'
|
177
177
|
end
|
@@ -179,10 +179,10 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
179
179
|
it 'should use the secure https url if secure_connection is set to true' do
|
180
180
|
subject.secure_connection = true
|
181
181
|
subject.access_key = TEST_ACCESS_KEY
|
182
|
-
subject.source_url.must_equal "#{secure_url}?base=#{source}&"\
|
182
|
+
_(subject.source_url).must_equal "#{secure_url}?base=#{source}&"\
|
183
183
|
"app_id=#{TEST_ACCESS_KEY}&"\
|
184
184
|
'prettyprint=0'
|
185
|
-
subject.source_url.must_include 'https://'
|
185
|
+
_(subject.source_url).must_include 'https://'
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
@@ -197,7 +197,7 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
197
197
|
it 'should update itself with exchange rates from OpenexchangeratesBank' do
|
198
198
|
subject.rates.keys.each do |currency|
|
199
199
|
next unless Money::Currency.find(currency)
|
200
|
-
subject.get_rate('USD', currency).must_be :>, 0
|
200
|
+
_(subject.get_rate('USD', currency)).must_be :>, 0
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
@@ -217,7 +217,7 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
217
217
|
subject.add_rate('USD', 'WTF', 2)
|
218
218
|
subject.add_rate('WTF', 'USD', 2)
|
219
219
|
subject.exchange_with(5000.to_money('WTF'), 'USD').cents
|
220
|
-
subject.exchange_with(5000.to_money('WTF'), 'USD').cents.wont_equal 0
|
220
|
+
_(subject.exchange_with(5000.to_money('WTF'), 'USD').cents).wont_equal 0
|
221
221
|
end
|
222
222
|
end
|
223
223
|
end
|
@@ -229,7 +229,7 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
229
229
|
end
|
230
230
|
|
231
231
|
it 'should raise an error if no access key is set' do
|
232
|
-
proc { subject.update_rates }.must_raise Money::Bank::NoAccessKey
|
232
|
+
_(proc { subject.update_rates }).must_raise Money::Bank::NoAccessKey
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -253,11 +253,11 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
253
253
|
describe 'when the ttl has expired' do
|
254
254
|
it 'should update the rates' do
|
255
255
|
Timecop.freeze(subject.rates_timestamp + 1000) do
|
256
|
-
subject.get_rate('USD', 'EUR').must_equal @old_usd_eur_rate
|
256
|
+
_(subject.get_rate('USD', 'EUR')).must_equal @old_usd_eur_rate
|
257
257
|
end
|
258
258
|
Timecop.freeze(subject.rates_timestamp + 1001) do
|
259
|
-
subject.get_rate('USD', 'EUR').wont_equal @old_usd_eur_rate
|
260
|
-
subject.get_rate('USD', 'EUR').must_equal @new_usd_eur_rate
|
259
|
+
_(subject.get_rate('USD', 'EUR')).wont_equal @old_usd_eur_rate
|
260
|
+
_(subject.get_rate('USD', 'EUR')).must_equal @new_usd_eur_rate
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
@@ -265,7 +265,7 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
265
265
|
Timecop.freeze(subject.rates_timestamp + 1001) do
|
266
266
|
exp_time = subject.rates_timestamp + 1000
|
267
267
|
subject.expire_rates!
|
268
|
-
subject.rates_expiration.must_equal exp_time
|
268
|
+
_(subject.rates_expiration).must_equal exp_time
|
269
269
|
end
|
270
270
|
end
|
271
271
|
end
|
@@ -275,7 +275,7 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
275
275
|
subject.update_rates
|
276
276
|
exp_time = subject.rates_expiration
|
277
277
|
subject.expire_rates!
|
278
|
-
subject.rates_expiration.must_equal exp_time
|
278
|
+
_(subject.rates_expiration).must_equal exp_time
|
279
279
|
end
|
280
280
|
end
|
281
281
|
end
|
@@ -294,12 +294,12 @@ describe Money::Bank::OpenexchangeratesBank do
|
|
294
294
|
it 'should return 1970-01-01 datetime if no rates' do
|
295
295
|
stub(subject).open_url { '' }
|
296
296
|
subject.update_rates
|
297
|
-
subject.rates_timestamp.must_equal Time.at(0)
|
297
|
+
_(subject.rates_timestamp).must_equal Time.at(0)
|
298
298
|
end
|
299
299
|
|
300
300
|
it 'should return a Time object' do
|
301
301
|
subject.update_rates
|
302
|
-
subject.rates_timestamp.class.must_equal Time
|
302
|
+
_(subject.rates_timestamp.class).must_equal Time
|
303
303
|
end
|
304
304
|
end
|
305
305
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money-openexchangerates-bank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Egon Zemmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: money
|
@@ -185,11 +185,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
|
-
|
189
|
-
rubygems_version: 2.5.2
|
188
|
+
rubygems_version: 3.2.0
|
190
189
|
signing_key:
|
191
190
|
specification_version: 4
|
192
191
|
summary: A gem that calculates the exchange rate using published rates from openexchangerates.org.
|
193
192
|
test_files:
|
194
193
|
- test/openexchangerates_bank_test.rb
|
195
|
-
has_rdoc:
|