money-open-exchange-rates 2.0.0 → 2.0.1
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.
- checksums.yaml +4 -4
- data/History.md +6 -0
- data/lib/money/bank/open_exchange_rates_bank.rb +17 -4
- data/lib/open_exchange_rates_bank/version.rb +1 -1
- data/test/data/partial_latest.json +16 -0
- data/test/open_exchange_rates_bank_test.rb +43 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b5f63af5ef2482e223249c50e9972e84c4f9aaa3bcec4b3052089ee3b60a237
|
|
4
|
+
data.tar.gz: aa6a135ef6dea76c5ca26739dcdabfe5ba2eac6bf83eba3c8b060f54c5357dc6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a78deced5445998e4fd6dd9cfa442753dca96bdbeabae0fbf0611e8c1274542030de8ed5be8f7b20a670693095370cb4a72e9a205ac556c1ce075f987ed128e5
|
|
7
|
+
data.tar.gz: b865cbfd1b40ab43f186aa99e1af7b01314eb90a46cecd586634b2b9e4a83614c99f555bf2aa3c7dd8419aa4faea85429026814f6c5299e657fba015c9d728a8
|
data/History.md
CHANGED
|
@@ -187,15 +187,14 @@ class Money
|
|
|
187
187
|
# @return [Array] Array of exchange rates
|
|
188
188
|
def update_rates
|
|
189
189
|
store.transaction do
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
rate = exchange_rate.last
|
|
193
|
-
currency = exchange_rate.first
|
|
190
|
+
new_rates = exchange_rates
|
|
191
|
+
new_rates.each do |currency, rate|
|
|
194
192
|
next unless Money::Currency.find(currency)
|
|
195
193
|
|
|
196
194
|
set_rate(source, currency, rate)
|
|
197
195
|
set_rate(currency, source, 1.0 / rate)
|
|
198
196
|
end
|
|
197
|
+
clear_cross_rates_for(new_rates)
|
|
199
198
|
end
|
|
200
199
|
end
|
|
201
200
|
|
|
@@ -438,6 +437,20 @@ class Money
|
|
|
438
437
|
add_rate(iso_from, iso_to, nil)
|
|
439
438
|
end
|
|
440
439
|
end
|
|
440
|
+
|
|
441
|
+
# Clears cross-rates for currencies present in new_rates
|
|
442
|
+
# Cross-rates are calculated on next access via calc_pair_rate_using_base
|
|
443
|
+
# Direct rates (source -> X) are not cleared, just overwritten
|
|
444
|
+
#
|
|
445
|
+
# @param new_rates [Hash] Rates hash from API response
|
|
446
|
+
def clear_cross_rates_for(new_rates)
|
|
447
|
+
store.each_rate do |iso_from, iso_to|
|
|
448
|
+
next if iso_from == source || iso_to == source
|
|
449
|
+
next unless new_rates.key?(iso_from) || new_rates.key?(iso_to)
|
|
450
|
+
|
|
451
|
+
add_rate(iso_from, iso_to, nil)
|
|
452
|
+
end
|
|
453
|
+
end
|
|
441
454
|
end
|
|
442
455
|
end
|
|
443
456
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"disclaimer": "Exchange rates are provided for informational purposes only.",
|
|
3
|
+
"license": "Data sourced from various providers.",
|
|
4
|
+
"timestamp": 1414008100,
|
|
5
|
+
"base": "USD",
|
|
6
|
+
"rates": {
|
|
7
|
+
"AED": 3.67304,
|
|
8
|
+
"AUD": 1.139103,
|
|
9
|
+
"BBD": 2,
|
|
10
|
+
"CAD": 1.124161,
|
|
11
|
+
"CHF": 0.951922,
|
|
12
|
+
"GBP": 0.62292,
|
|
13
|
+
"JPY": 107.0718,
|
|
14
|
+
"USD": 1
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -533,5 +533,48 @@ describe Money::Bank::OpenExchangeRatesBank do
|
|
|
533
533
|
end
|
|
534
534
|
end
|
|
535
535
|
end
|
|
536
|
+
|
|
537
|
+
describe 'missing currencies' do
|
|
538
|
+
let(:oer_partial_path) do
|
|
539
|
+
data_file('partial_latest.json')
|
|
540
|
+
end
|
|
541
|
+
|
|
542
|
+
before do
|
|
543
|
+
add_to_webmock(subject)
|
|
544
|
+
# see test/data/latest.json +52
|
|
545
|
+
@latest_usd_eur_rate = 0.79085
|
|
546
|
+
# see test/data/latest.json +33
|
|
547
|
+
@latest_usd_cad_rate = 1.124161
|
|
548
|
+
subject.update_rates
|
|
549
|
+
end
|
|
550
|
+
|
|
551
|
+
it 'should preserve direct rates' do
|
|
552
|
+
_(subject.get_rate('USD', 'EUR')).must_equal @latest_usd_eur_rate
|
|
553
|
+
subject.cache = nil
|
|
554
|
+
stub_request(:get, subject.source_url)
|
|
555
|
+
.to_return(status: 200, body: File.read(oer_partial_path))
|
|
556
|
+
subject.update_rates
|
|
557
|
+
_(subject.get_rate('USD', 'EUR')).must_equal @latest_usd_eur_rate
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
it 'should update rates for currencies in response' do
|
|
561
|
+
_(subject.get_rate('USD', 'CAD')).must_equal @latest_usd_cad_rate
|
|
562
|
+
subject.cache = nil
|
|
563
|
+
stub_request(:get, subject.source_url)
|
|
564
|
+
.to_return(status: 200, body: File.read(oer_partial_path))
|
|
565
|
+
subject.update_rates
|
|
566
|
+
_(subject.get_rate('USD', 'CAD')).must_equal @latest_usd_cad_rate
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
it 'should exchange with preserved rates' do
|
|
570
|
+
money = Money.new(100, 'USD')
|
|
571
|
+
_(subject.exchange_with(money, 'EUR')).must_equal Money.new(79, 'EUR')
|
|
572
|
+
subject.cache = nil
|
|
573
|
+
stub_request(:get, subject.source_url)
|
|
574
|
+
.to_return(status: 200, body: File.read(oer_partial_path))
|
|
575
|
+
subject.update_rates
|
|
576
|
+
_(subject.exchange_with(money, 'EUR')).must_equal Money.new(79, 'EUR')
|
|
577
|
+
end
|
|
578
|
+
end
|
|
536
579
|
end
|
|
537
580
|
# rubocop:enable Metrics/BlockLength
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: money-open-exchange-rates
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Laurent Arnoud
|
|
@@ -153,6 +153,7 @@ files:
|
|
|
153
153
|
- test/data/access_restricted_error.json
|
|
154
154
|
- test/data/app_id_inactive.json
|
|
155
155
|
- test/data/latest.json
|
|
156
|
+
- test/data/partial_latest.json
|
|
156
157
|
- test/integration/Gemfile
|
|
157
158
|
- test/integration/Gemfile.lock
|
|
158
159
|
- test/integration/api.rb
|