@@ -7,39 +7,45 @@ module WithIntegrationRoutingPatch # :nodoc:
77 module ClassMethods
88 def with_routing ( &block )
99 old_routes = nil
10+ old_routes_call_method = nil
1011 old_integration_session = nil
1112
1213 setup do
1314 old_routes = app . routes
15+ old_routes_call_method = old_routes . method ( :call )
1416 old_integration_session = integration_session
1517 create_routes ( &block )
1618 end
1719
1820 teardown do
19- reset_routes ( old_routes , old_integration_session )
21+ reset_routes ( old_routes , old_routes_call_method , old_integration_session )
2022 end
2123 end
2224 end
2325
2426 def with_routing ( &block )
2527 old_routes = app . routes
28+ old_routes_call_method = old_routes . method ( :call )
2629 old_integration_session = integration_session
2730 create_routes ( &block )
2831 ensure
29- reset_routes ( old_routes , old_integration_session )
32+ reset_routes ( old_routes , old_routes_call_method , old_integration_session )
3033 end
3134
3235 private
3336
3437 def create_routes
3538 app = self . app
3639 routes = ActionDispatch ::Routing ::RouteSet . new
37- rack_app = app . config . middleware . build ( routes )
40+
41+ @original_routes ||= app . routes
42+ @original_routes . singleton_class . redefine_method ( :call , &routes . method ( :call ) )
43+
3844 https = integration_session . https?
3945 host = integration_session . host
4046
4147 app . instance_variable_set ( :@routes , routes )
42- app . instance_variable_set ( :@app , rack_app )
48+
4349 @integration_session = Class . new ( ActionDispatch ::Integration ::Session ) do
4450 include app . routes . url_helpers
4551 include app . routes . mounted_helpers
@@ -51,11 +57,9 @@ def create_routes
5157 yield routes
5258 end
5359
54- def reset_routes ( old_routes , old_integration_session )
55- old_rack_app = app . config . middleware . build ( old_routes )
56-
60+ def reset_routes ( old_routes , old_routes_call_method , old_integration_session )
5761 app . instance_variable_set ( :@routes , old_routes )
58- app . instance_variable_set ( :@app , old_rack_app )
62+ @original_routes . singleton_class . redefine_method ( :call , & old_routes_call_method )
5963 @integration_session = old_integration_session
6064 @routes = old_routes
6165 end
0 commit comments