@@ -7,39 +7,45 @@ module WithIntegrationRoutingPatch # :nodoc:
7
7
module ClassMethods
8
8
def with_routing ( &block )
9
9
old_routes = nil
10
+ old_routes_call_method = nil
10
11
old_integration_session = nil
11
12
12
13
setup do
13
14
old_routes = app . routes
15
+ old_routes_call_method = old_routes . method ( :call )
14
16
old_integration_session = integration_session
15
17
create_routes ( &block )
16
18
end
17
19
18
20
teardown do
19
- reset_routes ( old_routes , old_integration_session )
21
+ reset_routes ( old_routes , old_routes_call_method , old_integration_session )
20
22
end
21
23
end
22
24
end
23
25
24
26
def with_routing ( &block )
25
27
old_routes = app . routes
28
+ old_routes_call_method = old_routes . method ( :call )
26
29
old_integration_session = integration_session
27
30
create_routes ( &block )
28
31
ensure
29
- reset_routes ( old_routes , old_integration_session )
32
+ reset_routes ( old_routes , old_routes_call_method , old_integration_session )
30
33
end
31
34
32
35
private
33
36
34
37
def create_routes
35
38
app = self . app
36
39
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
+
38
44
https = integration_session . https?
39
45
host = integration_session . host
40
46
41
47
app . instance_variable_set ( :@routes , routes )
42
- app . instance_variable_set ( :@app , rack_app )
48
+
43
49
@integration_session = Class . new ( ActionDispatch ::Integration ::Session ) do
44
50
include app . routes . url_helpers
45
51
include app . routes . mounted_helpers
@@ -51,11 +57,9 @@ def create_routes
51
57
yield routes
52
58
end
53
59
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 )
57
61
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 )
59
63
@integration_session = old_integration_session
60
64
@routes = old_routes
61
65
end
0 commit comments