Skip to content

Commit

Permalink
Merge pull request #64 from anton-smagin/clear-cross-courses
Browse files Browse the repository at this point in the history
  • Loading branch information
spk committed Sep 7, 2020
2 parents fd6794b + 0de0fc8 commit 62df981
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/money/bank/open_exchange_rates_bank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def update_rates
set_rate(source, currency, rate)
set_rate(currency, source, 1.0 / rate)
end
clear_calculated_pair_rates!
end

# Alias super method
Expand Down Expand Up @@ -414,6 +415,17 @@ def calc_pair_rate_using_base(from_currency, to_currency, opts)
add_rate(from_currency, to_currency, rate)
rate
end

# Clears calculated rates in store
#
# @return [Hash] All rates from store as Hash
def clear_calculated_pair_rates!
store.each_rate do |iso_from, iso_to|
next if iso_from == source || iso_to == source

add_rate(iso_from, iso_to, nil)
end
end
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/open_exchange_rates_bank_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@
add_to_webmock(subject)
# see test/latest.json +52
@latest_usd_eur_rate = 0.79085
@latest_chf_eur_rate = 0.830792859
# see test/2015-01-01.json +52
@old_usd_eur_rate = 0.830151
@old_chf_eur_rate = 0.832420177
subject.update_rates
end

Expand All @@ -426,6 +428,14 @@
subject.update_rates
_(subject.get_rate('USD', 'EUR')).must_equal @old_usd_eur_rate
end

it 'should update cross courses' do
subject.get_rate('CHF', 'EUR').must_equal @latest_chf_eur_rate
subject.date = '2015-01-01'
add_to_webmock(subject, oer_historical_path)
subject.update_rates
_(subject.get_rate('CHF', 'EUR')).must_equal @old_chf_eur_rate
end
end

describe 'source currency' do
Expand Down

0 comments on commit 62df981

Please sign in to comment.