From ec3be4a878c0cd4afad7a3443cb484526c1b79bd Mon Sep 17 00:00:00 2001 From: Stef Schenkelaars Date: Thu, 16 Dec 2021 10:14:43 +0100 Subject: [PATCH] Add support for rails 7 Since rails 7 adds an `encrypt` class method, this conflicted with the Lockbox class method. This commit explicitly uses lockbox and adds rails 7 to the test matrix. See: https://github.com/Drieam/keypairs/issues/8 --- .github/workflows/ci.yml | 14 +++++++------- .github/workflows/publish.yml | 4 ++++ .gitignore | 2 ++ .rubocop.yml | 3 ++- .ruby-version | 1 - Appraisals | 9 +++++++++ Gemfile.lock | 7 ++++++- gemfiles/rails_6.gemfile | 7 +++++++ gemfiles/rails_7.gemfile | 7 +++++++ keypairs.gemspec | 3 ++- lib/keypair.rb | 2 +- 11 files changed, 47 insertions(+), 12 deletions(-) delete mode 100644 .ruby-version create mode 100644 Appraisals create mode 100644 gemfiles/rails_6.gemfile create mode 100644 gemfiles/rails_7.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ddec06..2980f73 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,11 +9,9 @@ jobs: - uses: ruby/setup-ruby@v1 with: + ruby-version: 3.0 bundler-cache: true - - name: Install gems - run: bundle install - - name: Setup reviewdog uses: reviewdog/action-setup@v1 @@ -27,21 +25,23 @@ jobs: fail-fast: false matrix: ruby: - - 2.6 - 2.7 - '3.0' + gemfile: + - rails_6 + - rails_7 runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v2 + - name: Set BUNDLE_GEMFILE + run: echo 'BUNDLE_GEMFILE=${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile' >> $GITHUB_ENV + - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - name: Install gems - run: bundle install - - name: Run RSpec run: bundle exec rspec --format RSpec::Github::Formatter diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a28adf2..1eb86dc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -12,6 +12,8 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0 - name: Setup GitHub Package Registry credentials run: | @@ -38,6 +40,8 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0 - name: Replace version by tag value run: sed -i "s/'[0-9]\.[0-9]\..*'/'${GITHUB_REF##*/}'/" lib/keypairs/version.rb diff --git a/.gitignore b/.gitignore index b6f8156..ab8a574 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ tmp/ # rspec failure tracking .rspec_status +# Appraisals gemfile locks +gemfiles/*.gemfile.lock diff --git a/.rubocop.yml b/.rubocop.yml index 5ef5483..5be7373 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,9 +3,10 @@ require: - rubocop-rails # Rails-specific analysis AllCops: - TargetRubyVersion: 2.6 + TargetRubyVersion: 2.7 NewCops: enable Exclude: + - 'gemfiles/*' - 'tmp/**/*' - 'vendor/**/*' diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 37c2961..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.7.2 diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..699dacd --- /dev/null +++ b/Appraisals @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +appraise 'rails-6' do + gem 'rails', '~> 6.1' +end + +appraise 'rails-7' do + gem 'rails', '~> 7.0' +end diff --git a/Gemfile.lock b/Gemfile.lock index 23b3a46..cbcba58 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,6 +34,10 @@ GEM minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) + appraisal (2.4.1) + bundler + rake + thor (>= 0.14.0) ast (2.4.2) brakeman (5.1.2) builder (3.2.4) @@ -136,6 +140,7 @@ PLATFORMS ruby DEPENDENCIES + appraisal brakeman combustion database_cleaner-active_record @@ -150,4 +155,4 @@ DEPENDENCIES timecop BUNDLED WITH - 2.1.4 + 2.2.32 diff --git a/gemfiles/rails_6.gemfile b/gemfiles/rails_6.gemfile new file mode 100644 index 0000000..c34b486 --- /dev/null +++ b/gemfiles/rails_6.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 6.1" + +gemspec path: "../" diff --git a/gemfiles/rails_7.gemfile b/gemfiles/rails_7.gemfile new file mode 100644 index 0000000..9d2735b --- /dev/null +++ b/gemfiles/rails_7.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 7.0" + +gemspec path: "../" diff --git a/keypairs.gemspec b/keypairs.gemspec index 636d63d..341b01c 100644 --- a/keypairs.gemspec +++ b/keypairs.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| MESSAGE spec.description = spec.summary spec.license = 'MIT' - spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0') + spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0') spec.metadata['homepage_uri'] = spec.homepage spec.metadata['source_code_uri'] = 'https://github.com/Drieam/keypairs' @@ -29,6 +29,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'jwt', '~> 2.1' # Working with JSON Web Tokens spec.add_dependency 'lockbox', '~> 0.4' # Encrypt and decrypt attributes + spec.add_development_dependency 'appraisal' # Test against multiple gem versions spec.add_development_dependency 'brakeman' # Static analysis security vulnerability scanner spec.add_development_dependency 'combustion' # Test rails engines spec.add_development_dependency 'database_cleaner-active_record' # Ensure clean state for testing diff --git a/lib/keypair.rb b/lib/keypair.rb index 7dfc324..5abbcd8 100644 --- a/lib/keypair.rb +++ b/lib/keypair.rb @@ -38,7 +38,7 @@ class Keypair < ActiveRecord::Base ALGORITHM = 'RS256' ROTATION_INTERVAL = 1.month - encrypts :_keypair + lockbox_encrypts :_keypair validates :_keypair, presence: true validates :jwk_kid, presence: true