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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a04f2f4222945d437a7c84bfed72c8fbc36188644d00da13528a677eda9515a
4
- data.tar.gz: eb7c523fb8d74a9573ea65f8779fa5a41748b477dbc6f7ca9ceef5cde50de59a
3
+ metadata.gz: 3b5f63af5ef2482e223249c50e9972e84c4f9aaa3bcec4b3052089ee3b60a237
4
+ data.tar.gz: aa6a135ef6dea76c5ca26739dcdabfe5ba2eac6bf83eba3c8b060f54c5357dc6
5
5
  SHA512:
6
- metadata.gz: 508710569f6c2ca135fc5f09047ab20137b5c6ed6e93496c4b02925bdcc85e6f6fbb0a31b7d959534e82649f1302e50a0f6a7e4c06106c8bfc41cc170ee9b1ae
7
- data.tar.gz: f2dc857c17c69a5c4faec4bd432bdd3ff89091a24642715c56a0f1f99525118e3199653f1729d33227938ad6d3c943914405b893674be2258650cb65632371bb
6
+ metadata.gz: a78deced5445998e4fd6dd9cfa442753dca96bdbeabae0fbf0611e8c1274542030de8ed5be8f7b20a670693095370cb4a72e9a205ac556c1ce075f987ed128e5
7
+ data.tar.gz: b865cbfd1b40ab43f186aa99e1af7b01314eb90a46cecd586634b2b9e4a83614c99f555bf2aa3c7dd8419aa4faea85429026814f6c5299e657fba015c9d728a8
data/History.md CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ 2.0.1 / 2026-01-21
3
+ ==================
4
+
5
+ * Merge pull request #75 from @ps-97 / adarsh/preserve-rates-on-partial-api-response
6
+ * fix: preserve rates for currencies missing from API response
7
+
2
8
  2.0.0 / 2025-12-23
3
9
  ==================
4
10
 
@@ -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
- clear_rates!
191
- exchange_rates.each do |exchange_rate|
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Module for version constant
4
4
  module OpenExchangeRatesBank
5
- VERSION = '2.0.0'
5
+ VERSION = '2.0.1'
6
6
  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.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