@@ -20,20 +20,46 @@ def before_setup
2020 end
2121end
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+
2344class 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,12 +71,14 @@ 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+ old_app = self . class . app
75+ begin
76+ self . class . app = self . class . build_app ( set , options )
5277
53- yield
78+ yield
79+ ensure
80+ self . class . app = old_app
81+ end
5482 end
5583 end
5684
@@ -63,17 +91,4 @@ def with_store(class_name)
6391 end
6492end
6593
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-
7994ActiveSupport ::TestCase . test_order = :random
0 commit comments