Skip to content

Fix test suite with Rails 7.2+ #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ jobs:
fail-fast: false
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3']
rails: ['7.0', '7.1', 'edge']
rails: ['7.0', '7.1', '7.2', '8.0', 'edge']
exclude:
- ruby: '2.7'
rails: '7.2'
- ruby: '2.7'
rails: '8.0'
- ruby: '2.7'
rails: 'edge'
- ruby: '3.0'
rails: '7.2'
- ruby: '3.0'
rails: '8.0'
- ruby: '3.0'
rails: 'edge'
- ruby: '3.1'
rails: '8.0'
- ruby: '3.1'
rails: 'edge'
env:
BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile
Expand Down
11 changes: 11 additions & 0 deletions gemfiles/rails_7.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source "https://rubygems.org"

gem "actionpack", github: "rails/rails", branch: "7-2-stable"
gem "activerecord", github: "rails/rails", branch: "7-2-stable"
gem "railties", github: "rails/rails", branch: "7-2-stable"

gem "rack", ">= 2.2.4", "< 4"
gem "sqlite3"

gemspec :path => "../"

11 changes: 11 additions & 0 deletions gemfiles/rails_8.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source "https://rubygems.org"

gem "actionpack", github: "rails/rails", branch: "8-0-stable"
gem "activerecord", github: "rails/rails", branch: "8-0-stable"
gem "railties", github: "rails/rails", branch: "8-0-stable"

gem "rack", ">= 2.2.4", "< 4"
gem "sqlite3"

gemspec :path => "../"

53 changes: 34 additions & 19 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,46 @@ def before_setup
end
end

class RoutedRackApp
class Config < Struct.new(:middleware)
end

attr_reader :routes

def initialize(routes, &blk)
@routes = routes
@stack = ActionDispatch::MiddlewareStack.new(&blk)
@app = @stack.build(@routes)
end

def call(env)
@app.call(env)
end

def config
Config.new(@stack)
end
end

class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
include ActionDispatch::SharedRoutes

def self.build_app(routes = nil)
def self.build_app(routes, options)
RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
middleware.use ActionDispatch::DebugExceptions
middleware.use ActionDispatch::ActionableExceptions
middleware.use ActionDispatch::Callbacks
middleware.use ActionDispatch::Cookies
middleware.use ActionDispatch::Flash
middleware.use Rack::MethodOverride
middleware.use Rack::Head
middleware.use ActionDispatch::Session::ActiveRecordStore, options.reverse_merge(key: "_session_id")
yield(middleware) if block_given?
end
end

self.app = build_app(nil, {})

private

def with_test_route_set(options = {})
Expand All @@ -45,12 +71,14 @@ def with_test_route_set(options = {})
actions.each { |action| get action, controller: "#{controller_namespace}/test" }
end

@app = self.class.build_app(set) do |middleware|
middleware.use ActionDispatch::Session::ActiveRecordStore, options.reverse_merge(:key => '_session_id')
middleware.delete ActionDispatch::ShowExceptions
end
old_app = self.class.app
begin
self.class.app = self.class.build_app(set, options)

yield
yield
ensure
self.class.app = old_app
end
end
end

Expand All @@ -63,17 +91,4 @@ def with_store(class_name)
end
end

class RoutedRackApp
attr_reader :routes

def initialize(routes, &blk)
@routes = routes
@stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes)
end

def call(env)
@stack.call(env)
end
end

ActiveSupport::TestCase.test_order = :random
4 changes: 3 additions & 1 deletion test/logger_silencer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def setup
def test_log_silencer_with_logger_not_raise_exception
with_logger ActiveSupport::Logger.new(Tempfile.new("tempfile")) do
with_test_route_set do
get "/set_session_value"
assert_nothing_raised do
get "/set_session_value"
end
end
end
end
Expand Down