From d93cbbaf1eba91d43af7c48647297c24fdbb83c4 Mon Sep 17 00:00:00 2001 From: Guillaume Hain Date: Wed, 5 Mar 2025 13:46:53 +0100 Subject: [PATCH] Adds support for Ruby 3.2 and Rails 7.0 --- .github/workflows/ci.yml | 46 ++++++++++--------- Earthfile | 10 ++-- Gemfile | 6 ++- README.md | 7 +-- app/helpers/devise_gauth_helper.rb | 9 ++++ app/views/devise/displayqr/show.html.erb | 4 ++ devise_gauth.gemspec | 2 +- docker-compose-earthly.yml | 2 - docker-compose.yml | 2 - test/orm/active_record.rb | 5 +- .../app/views/devise/displayqr/show.html.erb | 4 ++ test/rails_app/config/application.rb | 11 +++++ test/rails_app/script/rails | 0 13 files changed, 72 insertions(+), 36 deletions(-) create mode 100644 app/helpers/devise_gauth_helper.rb mode change 100644 => 100755 test/rails_app/script/rails diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea25f51..c4ceb32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: matrix: include: # - # Rails 4.x branch + # Rails 4.x series # # Rails 4.2 compatible versions - ruby: 2.5 @@ -19,7 +19,7 @@ jobs: devise: 4.8.1 # - # Rails 5.x branch + # Rails 5.x series # # Rails 5.0 compatible versions - ruby: 2.5 # We should use 2.4 but Nokogiri requires 2.5 @@ -39,7 +39,7 @@ jobs: devise: 4.8.1 # - # Rails 6.x branch + # Rails 6.x series # # Rails 6.0 compatible versions - ruby: 2.6 @@ -57,6 +57,24 @@ jobs: - ruby: 3.1 rails: 6.1.7.10 devise: 4.9.4 + + # + # Rails 7.x series + # + - ruby: 3.1 + rails: 7.0.8.7 + devise: 4.9.4 + - ruby: 3.2 + rails: 7.0.8.7 + devise: 4.9.4 + # This can't work since the `test/rails_app/` needs to be upgraded + # See https://github.com/Pharmony/devise_gauth/issues/12 + # - ruby: 3.2 + # rails: 7.1.5.1 + # devise: 4.9.4 + # - ruby: 3.3 + # rails: 7.2.2.1 + # devise: 4.9.4 runs-on: ubuntu-latest name: RSpec suite (Ruby ${{ matrix.ruby }}/Rails ${{ matrix.rails }}/Devise ${{ matrix.devise }}) env: @@ -67,28 +85,14 @@ jobs: EARTHLY_RUBY_VERSION: ${{ matrix.ruby }} FORCE_COLOR: 1 steps: - - uses: actions/checkout@v3 - - name: Put back the git branch into git (Earthly uses it for tagging) - run: | - branch="" - if [ -n "$GITHUB_HEAD_REF" ]; then - branch="$GITHUB_HEAD_REF" - else - branch="${GITHUB_REF##*/}" - fi - git checkout -b "$branch" || true + - uses: earthly/actions-setup@v1 + with: + version: v0.8.0 + - uses: actions/checkout@v4 - name: Docker Login run: docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN" - - name: Download latest earthly - run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.7.23/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" - name: Earthly version run: earthly --version - name: Run build run: | earthly --ci --allow-privileged --output +test --EARTHLY_RUBY_VERSION=$EARTHLY_RUBY_VERSION --EARTHLY_RAILS_VERSION=$EARTHLY_RAILS_VERSION --EARTHLY_DEVISE_VERSION=$EARTHLY_DEVISE_VERSION - if [ -f exit_code ]; then - exit $(cat exit_code) - else - echo "'exit_code' file missing, something failed in previous command" - exit 1 - fi diff --git a/Earthfile b/Earthfile index a60590e..44918f1 100644 --- a/Earthfile +++ b/Earthfile @@ -6,18 +6,18 @@ VERSION 0.7 # This allows one to change the running Ruby version with: # -# `earthly --allow-privileged +test --EARTHLY_RUBY_VERSION=3` -ARG --global EARTHLY_RUBY_VERSION=3.0.6 +# `earthly --allow-privileged +test --EARTHLY_RUBY_VERSION=3.2` +ARG --global EARTHLY_RUBY_VERSION=3.1.6 # This allows one to change the running Rails version with: # -# `earthly --allow-privileged +test --EARTHLY_RAILS_VERSION=7` -ARG --global EARTHLY_RAILS_VERSION=6.1.7.6 +# `earthly --allow-privileged +test --EARTHLY_RAILS_VERSION=7.1` +ARG --global EARTHLY_RAILS_VERSION=7.0.8.7 # This allows one to change the running Rails version with: # # `earthly --allow-privileged +test --EARTHLY_DEVISE_VERSION=4.8.1` -ARG --global EARTHLY_DEVISE_VERSION=4.9.3 +ARG --global EARTHLY_DEVISE_VERSION=4.9.4 FROM ruby:$EARTHLY_RUBY_VERSION WORKDIR /gem diff --git a/Gemfile b/Gemfile index e84cdf7..30511cd 100644 --- a/Gemfile +++ b/Gemfile @@ -21,7 +21,11 @@ gem 'factory_girl_rails' gem 'mocha', '~> 0.13.0' # With Ruby >= 3.0 if ruby_version >= Gem::Version.new('3.0.0') - gem 'nokogiri', '~> 1.13.0' + if Gem::Version.new(rails_min_version) < Gem::Version.new('7.0.0') + gem 'nokogiri', '~> 1.13.0' + else + gem 'nokogiri', '~> 1.15.0' + end else gem 'nokogiri', '~> 1.12.0' end diff --git a/README.md b/README.md index 4c7de19..470f565 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,12 @@ This is a fork of the [devise](https://github.com/plataformatec/devise) extension to allow your app to utilise [Google Authenticator](http://code.google.com/p/google-authenticator/) for Time-based One Time Passwords (TOTP). -The current version of this gem support Rails from version 4.2 (older versions -are requiring older version of Ruby, which is hard to maintain), until version -6.1.x.\ +The current version of this gem support Rails from version 4.2, until version +7.0.x.\ For more details see the `.github/workflows/ci.yml` file. +Rails 7.1 and 7.2 need more work, see issue [#12](https://github.com/Pharmony/devise_gauth/issues/12). + ## Installation Add the gem to your Gemfile (don't forget devise too): diff --git a/app/helpers/devise_gauth_helper.rb b/app/helpers/devise_gauth_helper.rb new file mode 100644 index 0000000..87ab2c3 --- /dev/null +++ b/app/helpers/devise_gauth_helper.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module DeviseGauthHelper + DEVISE_VERSION = Gem::Version.new(Gem::Specification.find_by_name('devise').version) + + def devise_4_6_and_above? + Gem::Version.new('4.6.0') <= DEVISE_VERSION + end +end diff --git a/app/views/devise/displayqr/show.html.erb b/app/views/devise/displayqr/show.html.erb index 47e108b..975b8ed 100644 --- a/app/views/devise/displayqr/show.html.erb +++ b/app/views/devise/displayqr/show.html.erb @@ -7,7 +7,11 @@ <% end %> <%= form_for(resource, as: resource_name, url: [resource_name, :displayqr], html: { method: :put }) do |f| %> + <% if devise_4_6_and_above? %> + <%= render "devise/shared/error_messages", resource: resource %> + <% else %> <%= devise_error_messages! %> + <% end %>

<%= I18n.t('nice_request', scope: 'devise.registration') %>

<%= f.label :gauth_enabled, I18n.t('qrstatus', scope: 'devise.registration') %>
<%= f.check_box :gauth_enabled %>

diff --git a/devise_gauth.gemspec b/devise_gauth.gemspec index 5575c54..4c95eb4 100644 --- a/devise_gauth.gemspec +++ b/devise_gauth.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |spec| spec.license = 'MIT' spec.required_ruby_version = if ENV.fetch('PUBLISHING_GEM', false) - ['>= 2.4', '< 3.2'] + ['>= 2.4', '< 3.3'] else ">= #{ENV.fetch('EARTHLY_RUBY_VERSION')}" end diff --git a/docker-compose-earthly.yml b/docker-compose-earthly.yml index 4c91741..0be7c0b 100644 --- a/docker-compose-earthly.yml +++ b/docker-compose-earthly.yml @@ -1,5 +1,3 @@ -version: '3' - name: devise_gauth services: diff --git a/docker-compose.yml b/docker-compose.yml index 4ba507c..dc4494e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3' - name: devise_gauth services: diff --git a/test/orm/active_record.rb b/test/orm/active_record.rb index f459093..22b09ca 100644 --- a/test/orm/active_record.rb +++ b/test/orm/active_record.rb @@ -11,9 +11,12 @@ ActiveRecord::Migrator.migrate(migration_scripts_path) elsif Rails.version >= '5.2' && Rails.version < '6.0' ActiveRecord::MigrationContext.new(migration_scripts_path).migrate -else +elsif Rails.version >= '6.0' && Rails.version < '7.1' ActiveRecord::MigrationContext.new( migration_scripts_path, ActiveRecord::Base.connection.schema_migration ).migrate +else + # Rails version 7.2 and newer + ActiveRecord::MigrationContext.new('db/migrate/').migrate end diff --git a/test/rails_app/app/views/devise/displayqr/show.html.erb b/test/rails_app/app/views/devise/displayqr/show.html.erb index 8c7a741..300cea1 100644 --- a/test/rails_app/app/views/devise/displayqr/show.html.erb +++ b/test/rails_app/app/views/devise/displayqr/show.html.erb @@ -7,7 +7,11 @@ <% end %> <%= form_for(resource, as: resource_name, url: [resource_name, :displayqr], html: { method: :put }) do |f| %> + <% if devise_4_6_and_above? %> + <%= render "devise/shared/error_messages", resource: resource %> + <% else %> <%= devise_error_messages! %> + <% end %>

<%= I18n.t('nice_request', scope: 'devise.registration') %>

<%= f.label :gauth_enabled, I18n.t('qrstatus', scope: 'devise.registration') %>
<%= f.check_box :gauth_enabled %>

diff --git a/test/rails_app/config/application.rb b/test/rails_app/config/application.rb index e2c9b2e..58ff72e 100644 --- a/test/rails_app/config/application.rb +++ b/test/rails_app/config/application.rb @@ -32,5 +32,16 @@ class Application < Rails::Application # was deprecated in Rails 6.0 and removed in Rails 6.1 config.active_record.sqlite3.represent_boolean_as_integer = true end + + if Rails.version >= '7.0' && Rails.version < '7.1' + # DEPRECATION WARNING: Using legacy connection handling is deprecated. + # Please set `legacy_connection_handling` to `false` in your application. + config.active_record.legacy_connection_handling = false + end + + config.active_support.cache_format_version = 6.1 if Rails.version >= '6.1' + config.active_support.cache_format_version = 7.0 if Rails.version >= '7.0' + config.active_support.cache_format_version = 7.1 if Rails.version >= '7.1' + config.active_support.cache_format_version = 7.2 if Rails.version >= '7.2' end end diff --git a/test/rails_app/script/rails b/test/rails_app/script/rails old mode 100644 new mode 100755