Skip to content

Commit 73ed1e9

Browse files
stevenharmanbyroot
authored andcommitted
Build an app instance compatible with with_routing
As of rails/rails#49819 the internals of `ActionDispatch::Assertions::RoutingAssertions` changed and the way we were building our app instance was no compatible with it. This gets us back to passing tests for Rails 7.2+. I hope 🤞
1 parent 31702d9 commit 73ed1e9

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

test/helper.rb

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,46 @@ def before_setup
2020
end
2121
end
2222

23+
class RoutedRackApp
24+
class Config < Struct.new(:middleware)
25+
end
26+
27+
attr_reader :routes
28+
29+
def initialize(routes, &blk)
30+
@routes = routes
31+
@stack = ActionDispatch::MiddlewareStack.new(&blk)
32+
@app = @stack.build(@routes)
33+
end
34+
35+
def call(env)
36+
@app.call(env)
37+
end
38+
39+
def config
40+
Config.new(@stack)
41+
end
42+
end
43+
2344
class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
2445
include ActionDispatch::SharedRoutes
2546

26-
def self.build_app(routes = nil)
47+
def self.build_app(routes, options)
2748
RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
2849
middleware.use ActionDispatch::DebugExceptions
50+
middleware.use ActionDispatch::ActionableExceptions
2951
middleware.use ActionDispatch::Callbacks
3052
middleware.use ActionDispatch::Cookies
3153
middleware.use ActionDispatch::Flash
54+
middleware.use Rack::MethodOverride
3255
middleware.use Rack::Head
56+
middleware.use ActionDispatch::Session::ActiveRecordStore, options.reverse_merge(key: "_session_id")
3357
yield(middleware) if block_given?
3458
end
3559
end
3660

61+
self.app = build_app(nil, {})
62+
3763
private
3864

3965
def with_test_route_set(options = {})
@@ -45,10 +71,7 @@ def with_test_route_set(options = {})
4571
actions.each { |action| get action, controller: "#{controller_namespace}/test" }
4672
end
4773

48-
@app = self.class.build_app(set) do |middleware|
49-
middleware.use ActionDispatch::Session::ActiveRecordStore, options.reverse_merge(:key => '_session_id')
50-
middleware.delete ActionDispatch::ShowExceptions
51-
end
74+
self.class.app = self.class.build_app(set, options)
5275

5376
yield
5477
end
@@ -63,17 +86,4 @@ def with_store(class_name)
6386
end
6487
end
6588

66-
class RoutedRackApp
67-
attr_reader :routes
68-
69-
def initialize(routes, &blk)
70-
@routes = routes
71-
@stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes)
72-
end
73-
74-
def call(env)
75-
@stack.call(env)
76-
end
77-
end
78-
7989
ActiveSupport::TestCase.test_order = :random

test/logger_silencer_test.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def setup
3939
def test_log_silencer_with_logger_not_raise_exception
4040
with_logger ActiveSupport::Logger.new(Tempfile.new("tempfile")) do
4141
with_test_route_set do
42-
get "/set_session_value"
42+
assert_nothing_raised do
43+
get "/set_session_value"
44+
end
4345
end
4446
end
4547
end

0 commit comments

Comments
 (0)