Skip to content

Commit

Permalink
Support rails 7.1 (#575)
Browse files Browse the repository at this point in the history
* add rails 7.1 gemfile

* add rails 7.1 to test workflow

* use symbols to show exceptions

Removes
```
DEPRECATION WARNING: Setting action_dispatch.show_exceptions to false is deprecated. Set to :none instead. (called from call at /home/runner/work/cucumber-rails/cucumber-rails/lib/cucumber/rails/action_dispatch.rb:14)
```

* deal with new raise_on_missing_callback_conditionals rails feature

Rails 7.1 introduces a new "Raise error on missing only unless" feature
(see rails/rails#43487).

The new feature is enabled by default. I rewrote the
auto-generated code in feature specs to comply to the new rule.
  • Loading branch information
mgrunberg authored Oct 12, 2023
1 parent 48d9f16 commit 1cf4099
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2']
gemfile: ['rails_5_2', 'rails_6_0', 'rails_6_1', 'rails_7_0']
gemfile: ['rails_5_2', 'rails_6_0', 'rails_6_1', 'rails_7_0', 'rails_7_1']
exclude:
# Latest ruby will test
# - all rails versions in current major
Expand All @@ -34,7 +34,9 @@ jobs:
- { ruby: '2.6', gemfile: 'rails_6_0' }
- { ruby: '2.6', gemfile: 'rails_6_1' }
- { ruby: '2.6', gemfile: 'rails_7_0' }
- { ruby: '2.6', gemfile: 'rails_7_1' }
- { ruby: '2.7', gemfile: 'rails_7_0' }
- { ruby: '2.7', gemfile: 'rails_7_1' }
# Ruby 3+ won't work with Rails 5.2: https://github.com/rails/rails/issues/40938
- { ruby: '3.0', gemfile: 'rails_5_2' }
- { ruby: '3.1', gemfile: 'rails_5_2' }
Expand Down
6 changes: 6 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ appraise 'rails_7_0' do
gem 'railties', '~> 7.0.0'
gem 'sqlite3', '~> 1.4'
end

appraise 'rails_7_1' do
gem 'activerecord'
gem 'railties', '~> 7.1.0'
gem 'sqlite3', '~> 1.4'
end
5 changes: 5 additions & 0 deletions features/emulate_javascript.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ Feature: Emulate Javascript
before_action except: :establish do
render text: 'denied', status: :forbidden and return false unless session[:verified]
end
# Rails 7.1 introduces raise_on_missing_callback_conditionals and it's on by default
def establish
raise "This action must be implemented in child controllers"
end
end
"""
And I write to "features/widgets.feature" with:
Expand Down
9 changes: 9 additions & 0 deletions gemfiles/rails_7_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord"
gem "railties", "~> 7.1.0"
gem "sqlite3", "~> 1.4"

gemspec path: "../"
9 changes: 8 additions & 1 deletion lib/cucumber/rails/action_dispatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ module ActionDispatch
module ShowExceptions
def call(env)
env['action_dispatch.show_detailed_exceptions'] = !ActionController::Base.allow_rescue
env['action_dispatch.show_exceptions'] = !env['action_dispatch.show_detailed_exceptions']

show_exceptions = !env['action_dispatch.show_detailed_exceptions']
if ::Rails.gem_version >= Gem::Version.new('7.1.0')
# Rails 7.1 deprecated `show_exceptions` boolean in in favor of symbols
show_exceptions = show_exceptions ? :all : :none
end

env['action_dispatch.show_exceptions'] = show_exceptions
super(env)
end
end
Expand Down

0 comments on commit 1cf4099

Please sign in to comment.