Skip to content

Commit 2241403

Browse files
authored
Merge pull request #124 from petergoldstein/feature/add_ruby_3_1_and_3_2_to_ci
Adds Ruby 3.1 and 3.2 to CI
2 parents 0552e11 + ef93686 commit 2241403

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

.github/workflows/ruby.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
ruby-version: ['2.6', '2.7', '3.0']
22+
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
2323

2424
steps:
25-
- uses: actions/checkout@v2
25+
- uses: actions/checkout@v3
2626
- name: Set up Ruby
2727
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
2828
# change this to (see https://github.com/ruby/setup-ruby#versioning):

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# eu_central_bank changelog
22

3+
* Update YAML loading from compatibility with recent Psych versions.
34
* Move Croatian Kuna (HRK) and Russian Ruble (RUB) to legacy currencies
45

56
## 1.7.0 (Nov 17 2021)

eu_central_bank.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
1414
s.add_dependency "nokogiri", RUBY_VERSION >= "2.1" ? "~> 1.9" : "~> 1.6.8"
1515
s.add_dependency "money", "~> 6.13", ">= 6.13.6"
1616

17-
s.add_development_dependency "rspec", "~> 3.5.0"
17+
s.add_development_dependency "rspec", "~> 3.12.0"
1818

1919
s.files = Dir.glob("lib/**/*") + %w(CHANGELOG.md LICENSE README.md)
2020
s.require_path = "lib"

lib/eu_central_bank.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ def import_rates(format, s, opts = {})
149149
when :ruby
150150
Marshal.load(s)
151151
when :yaml
152-
YAML.load(s)
152+
if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
153+
YAML.safe_load(s, permitted_classes: [ BigDecimal ])
154+
else
155+
YAML.safe_load(s, [ BigDecimal ], [], true)
156+
end
153157
end
154158

155159
data.each do |key, rate|

spec/eu_central_bank_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2-
require 'yaml'
32

43
describe "EuCentralBank" do
54
before(:each) do
@@ -11,7 +10,7 @@
1110
@tmp_history_cache_path = File.expand_path(@dir_path + '/tmp/exchange_rates_90_day.xml')
1211
@tmp_full_history_cache_path = File.expand_path(@dir_path + '/tmp/exchange_rates_all.xml')
1312
yml_cache_path = File.expand_path(@dir_path + '/exchange_rates.yml')
14-
@exchange_rates = YAML.load_file(yml_cache_path)
13+
@exchange_rates = load_exchange_rates_from_file(yml_cache_path)
1514
end
1615

1716
after(:each) do
@@ -146,7 +145,7 @@
146145

147146
it "should return the correct exchange rates using historical exchange" do
148147
yml_path = File.expand_path(File.dirname(__FILE__) + '/historical_exchange_rates.yml')
149-
historical_exchange_rates = YAML.load_file(yml_path)
148+
historical_exchange_rates = load_exchange_rates_from_file(yml_path)
150149
@bank.update_historical_rates(@history_cache_path)
151150

152151
EuCentralBank::CURRENCIES.each do |currency|
@@ -173,7 +172,7 @@
173172
@bank.update_rates(odd_rates)
174173

175174
10.times do
176-
rates = YAML.load(@bank.export_rates(:yaml))
175+
rates = load_exchange_rates(@bank.export_rates(:yaml))
177176
rates.delete('EUR_TO_EUR')
178177
rates = rates.values.collect(&:to_i)
179178
expect(rates.length).to eq(32)

spec/spec_helper.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
require 'eu_central_bank'
2+
require 'yaml'
23

34
I18n.enforce_available_locales = false
5+
6+
def load_exchange_rates_from_file(file)
7+
load_exchange_rates(File.open(file))
8+
end
9+
10+
def load_exchange_rates(input)
11+
if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
12+
::YAML.safe_load(input, permitted_classes: [ BigDecimal ])
13+
else
14+
::YAML.safe_load(input, [ BigDecimal ], [], true)
15+
end
16+
end

0 commit comments

Comments
 (0)