@@ -20,20 +20,46 @@ def before_setup
20
20
end
21
21
end
22
22
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
+
23
44
class ActionDispatch ::IntegrationTest < ActiveSupport ::TestCase
24
45
include ActionDispatch ::SharedRoutes
25
46
26
- def self . build_app ( routes = nil )
47
+ def self . build_app ( routes , options )
27
48
RoutedRackApp . new ( routes || ActionDispatch ::Routing ::RouteSet . new ) do |middleware |
28
49
middleware . use ActionDispatch ::DebugExceptions
50
+ middleware . use ActionDispatch ::ActionableExceptions
29
51
middleware . use ActionDispatch ::Callbacks
30
52
middleware . use ActionDispatch ::Cookies
31
53
middleware . use ActionDispatch ::Flash
54
+ middleware . use Rack ::MethodOverride
32
55
middleware . use Rack ::Head
56
+ middleware . use ActionDispatch ::Session ::ActiveRecordStore , options . reverse_merge ( key : "_session_id" )
33
57
yield ( middleware ) if block_given?
34
58
end
35
59
end
36
60
61
+ self . app = build_app ( nil , { } )
62
+
37
63
private
38
64
39
65
def with_test_route_set ( options = { } )
@@ -45,12 +71,14 @@ def with_test_route_set(options = {})
45
71
actions . each { |action | get action , controller : "#{ controller_namespace } /test" }
46
72
end
47
73
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
+ old_app = self . class . app
75
+ begin
76
+ self . class . app = self . class . build_app ( set , options )
52
77
53
- yield
78
+ yield
79
+ ensure
80
+ self . class . app = old_app
81
+ end
54
82
end
55
83
end
56
84
@@ -63,17 +91,4 @@ def with_store(class_name)
63
91
end
64
92
end
65
93
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
-
79
94
ActiveSupport ::TestCase . test_order = :random
0 commit comments