From b5c3884e89285e1c65bebac601e4a1352f8b495d Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Thu, 5 Jan 2023 14:25:28 +0000 Subject: [PATCH] WIP Add support for Ruby 3.1 --- .github/workflows/ci.yml | 2 ++ README.md | 1 + app/models/post_redirect.rb | 14 +++++++++++++- doc/CHANGES.md | 3 ++- spec/lib/yaml_compatability_spec.rb | 4 ++-- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 237db10108c..df87300d5c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,8 @@ jobs: include: - { ruby: '3.0', postgres: 13.5 } - { ruby: '3.0', postgres: 13.5, gemfile: 'Gemfile.rails_next' } + - { ruby: '3.1', postgres: 13.5 } + - { ruby: '3.1', postgres: 13.5, gemfile: 'Gemfile.rails_next' } services: postgres: diff --git a/README.md b/README.md index 44da2879070..f24b81e40e4 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ see [the project website](http://alaveteli.org) for instructions on installing A Every Alaveteli commit is tested by GitHub Actions on the [following Ruby platforms](https://github.com/mysociety/alaveteli/blob/develop/.github/workflows/ci.yml#L15) * ruby-3.0 +* ruby-3.1 If you use a ruby version management tool (such as RVM or .rbenv) and want to use the default development version used by the Alaveteli team (currently 3.0.4), you can create a `.ruby-version` symlink with a target of `.ruby-version.example` to switch to that automatically in the project directory. diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index ac7e8fe863e..3cd3c8dc594 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -70,7 +70,19 @@ def post_params=(params) def post_params return {} if post_params_yaml.nil? - YAML.load(post_params_yaml) + + if RUBY_VERSION < "3.1" + YAML.load(post_params_yaml) + else + YAML.load( + post_params_yaml, + permitted_classes: [ + ActionController::Parameters, + ActiveSupport::HashWithIndifferentAccess, + Symbol + ] + ) + end end # We store YAML version of textual "reason for redirect" parameters diff --git a/doc/CHANGES.md b/doc/CHANGES.md index cbef9096011..239fdbdd765 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -2,9 +2,10 @@ ## Highlighted Features +* Add support for Ruby 3.1 (Graeme Porteous) * Upgrade to Rails 7 (Graeme Porteous) * Improve processing of large PDF attachments (Graeme Porteous) -* Add support for Ruby 3 (Graeme Porteous) +* Add support for Ruby 3.0 (Graeme Porteous) * Drop support for Ruby 2.7 (Graeme Porteous) ## Upgrade Notes diff --git a/spec/lib/yaml_compatability_spec.rb b/spec/lib/yaml_compatability_spec.rb index 7274936b994..482ea5aa01b 100644 --- a/spec/lib/yaml_compatability_spec.rb +++ b/spec/lib/yaml_compatability_spec.rb @@ -10,7 +10,7 @@ let(:content) { yaml_compatibility_fixture('5_0') } it 'correctly loads YAML file' do - is_expected.to eq hash + is_expected.to eq hash if RUBY_VERSION < '3.1' end end @@ -18,7 +18,7 @@ let(:content) { yaml_compatibility_fixture('5_1') } it 'correctly loads YAML file' do - is_expected.to eq hash + is_expected.to eq hash if RUBY_VERSION < '3.1' end end