Skip to content

Commit

Permalink
Add support for rails 7
Browse files Browse the repository at this point in the history
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: #8
  • Loading branch information
StefSchenkelaars committed Dec 16, 2021
1 parent 2a2a45c commit ec3be4a
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 12 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ tmp/
# rspec failure tracking
.rspec_status

# Appraisals gemfile locks
gemfiles/*.gemfile.lock
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ require:
- rubocop-rails # Rails-specific analysis

AllCops:
TargetRubyVersion: 2.6
TargetRubyVersion: 2.7
NewCops: enable
Exclude:
- 'gemfiles/*'
- 'tmp/**/*'
- 'vendor/**/*'

Expand Down
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

9 changes: 9 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -136,6 +140,7 @@ PLATFORMS
ruby

DEPENDENCIES
appraisal
brakeman
combustion
database_cleaner-active_record
Expand All @@ -150,4 +155,4 @@ DEPENDENCIES
timecop

BUNDLED WITH
2.1.4
2.2.32
7 changes: 7 additions & 0 deletions gemfiles/rails_6.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.1"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/rails_7.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 7.0"

gemspec path: "../"
3 changes: 2 additions & 1 deletion keypairs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/keypair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ec3be4a

Please sign in to comment.