actionpack 7.1.5.1 → 8.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +308 -523
  3. data/README.rdoc +1 -1
  4. data/lib/abstract_controller/asset_paths.rb +6 -2
  5. data/lib/abstract_controller/base.rb +104 -105
  6. data/lib/abstract_controller/caching/fragments.rb +50 -53
  7. data/lib/abstract_controller/caching.rb +8 -3
  8. data/lib/abstract_controller/callbacks.rb +70 -62
  9. data/lib/abstract_controller/collector.rb +7 -7
  10. data/lib/abstract_controller/deprecator.rb +2 -0
  11. data/lib/abstract_controller/error.rb +2 -0
  12. data/lib/abstract_controller/helpers.rb +71 -84
  13. data/lib/abstract_controller/logger.rb +4 -1
  14. data/lib/abstract_controller/railties/routes_helpers.rb +2 -0
  15. data/lib/abstract_controller/rendering.rb +13 -13
  16. data/lib/abstract_controller/translation.rb +12 -13
  17. data/lib/abstract_controller/url_for.rb +8 -6
  18. data/lib/abstract_controller.rb +2 -0
  19. data/lib/action_controller/api/api_rendering.rb +2 -0
  20. data/lib/action_controller/api.rb +76 -72
  21. data/lib/action_controller/base.rb +199 -126
  22. data/lib/action_controller/caching.rb +16 -14
  23. data/lib/action_controller/deprecator.rb +2 -0
  24. data/lib/action_controller/form_builder.rb +21 -18
  25. data/lib/action_controller/log_subscriber.rb +23 -2
  26. data/lib/action_controller/metal/allow_browser.rb +133 -0
  27. data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
  28. data/lib/action_controller/metal/conditional_get.rb +217 -175
  29. data/lib/action_controller/metal/content_security_policy.rb +25 -24
  30. data/lib/action_controller/metal/cookies.rb +4 -2
  31. data/lib/action_controller/metal/data_streaming.rb +72 -63
  32. data/lib/action_controller/metal/default_headers.rb +5 -3
  33. data/lib/action_controller/metal/etag_with_flash.rb +3 -1
  34. data/lib/action_controller/metal/etag_with_template_digest.rb +17 -15
  35. data/lib/action_controller/metal/exceptions.rb +16 -9
  36. data/lib/action_controller/metal/flash.rb +13 -14
  37. data/lib/action_controller/metal/head.rb +15 -11
  38. data/lib/action_controller/metal/helpers.rb +63 -55
  39. data/lib/action_controller/metal/http_authentication.rb +209 -201
  40. data/lib/action_controller/metal/implicit_render.rb +17 -15
  41. data/lib/action_controller/metal/instrumentation.rb +16 -14
  42. data/lib/action_controller/metal/live.rb +177 -128
  43. data/lib/action_controller/metal/logging.rb +6 -4
  44. data/lib/action_controller/metal/mime_responds.rb +151 -142
  45. data/lib/action_controller/metal/parameter_encoding.rb +34 -32
  46. data/lib/action_controller/metal/params_wrapper.rb +57 -59
  47. data/lib/action_controller/metal/permissions_policy.rb +22 -12
  48. data/lib/action_controller/metal/rate_limiting.rb +92 -0
  49. data/lib/action_controller/metal/redirecting.rb +213 -94
  50. data/lib/action_controller/metal/renderers.rb +78 -57
  51. data/lib/action_controller/metal/rendering.rb +111 -77
  52. data/lib/action_controller/metal/request_forgery_protection.rb +182 -143
  53. data/lib/action_controller/metal/rescue.rb +20 -9
  54. data/lib/action_controller/metal/streaming.rb +118 -195
  55. data/lib/action_controller/metal/strong_parameters.rb +720 -530
  56. data/lib/action_controller/metal/testing.rb +2 -0
  57. data/lib/action_controller/metal/url_for.rb +17 -15
  58. data/lib/action_controller/metal.rb +86 -60
  59. data/lib/action_controller/railtie.rb +36 -15
  60. data/lib/action_controller/railties/helpers.rb +2 -0
  61. data/lib/action_controller/renderer.rb +41 -36
  62. data/lib/action_controller/structured_event_subscriber.rb +116 -0
  63. data/lib/action_controller/template_assertions.rb +4 -2
  64. data/lib/action_controller/test_case.rb +160 -131
  65. data/lib/action_controller.rb +5 -1
  66. data/lib/action_dispatch/constants.rb +8 -0
  67. data/lib/action_dispatch/deprecator.rb +2 -0
  68. data/lib/action_dispatch/http/cache.rb +163 -35
  69. data/lib/action_dispatch/http/content_disposition.rb +2 -0
  70. data/lib/action_dispatch/http/content_security_policy.rb +54 -39
  71. data/lib/action_dispatch/http/filter_parameters.rb +14 -8
  72. data/lib/action_dispatch/http/filter_redirect.rb +22 -1
  73. data/lib/action_dispatch/http/headers.rb +22 -22
  74. data/lib/action_dispatch/http/mime_negotiation.rb +89 -41
  75. data/lib/action_dispatch/http/mime_type.rb +25 -21
  76. data/lib/action_dispatch/http/mime_types.rb +3 -0
  77. data/lib/action_dispatch/http/param_builder.rb +187 -0
  78. data/lib/action_dispatch/http/param_error.rb +26 -0
  79. data/lib/action_dispatch/http/parameters.rb +14 -12
  80. data/lib/action_dispatch/http/permissions_policy.rb +25 -36
  81. data/lib/action_dispatch/http/query_parser.rb +55 -0
  82. data/lib/action_dispatch/http/rack_cache.rb +2 -0
  83. data/lib/action_dispatch/http/request.rb +141 -92
  84. data/lib/action_dispatch/http/response.rb +137 -77
  85. data/lib/action_dispatch/http/upload.rb +18 -16
  86. data/lib/action_dispatch/http/url.rb +187 -89
  87. data/lib/action_dispatch/journey/formatter.rb +21 -9
  88. data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
  89. data/lib/action_dispatch/journey/gtg/simulator.rb +34 -11
  90. data/lib/action_dispatch/journey/gtg/transition_table.rb +47 -53
  91. data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
  92. data/lib/action_dispatch/journey/nodes/node.rb +8 -6
  93. data/lib/action_dispatch/journey/parser.rb +99 -195
  94. data/lib/action_dispatch/journey/path/pattern.rb +4 -1
  95. data/lib/action_dispatch/journey/route.rb +54 -38
  96. data/lib/action_dispatch/journey/router/utils.rb +22 -27
  97. data/lib/action_dispatch/journey/router.rb +63 -83
  98. data/lib/action_dispatch/journey/routes.rb +11 -2
  99. data/lib/action_dispatch/journey/scanner.rb +46 -42
  100. data/lib/action_dispatch/journey/visitors.rb +57 -23
  101. data/lib/action_dispatch/journey/visualizer/fsm.js +4 -6
  102. data/lib/action_dispatch/journey.rb +2 -0
  103. data/lib/action_dispatch/log_subscriber.rb +7 -1
  104. data/lib/action_dispatch/middleware/actionable_exceptions.rb +2 -0
  105. data/lib/action_dispatch/middleware/assume_ssl.rb +8 -5
  106. data/lib/action_dispatch/middleware/callbacks.rb +3 -1
  107. data/lib/action_dispatch/middleware/cookies.rb +125 -106
  108. data/lib/action_dispatch/middleware/debug_exceptions.rb +37 -8
  109. data/lib/action_dispatch/middleware/debug_locks.rb +15 -13
  110. data/lib/action_dispatch/middleware/debug_view.rb +13 -5
  111. data/lib/action_dispatch/middleware/exception_wrapper.rb +18 -23
  112. data/lib/action_dispatch/middleware/executor.rb +19 -4
  113. data/lib/action_dispatch/middleware/flash.rb +63 -51
  114. data/lib/action_dispatch/middleware/host_authorization.rb +17 -15
  115. data/lib/action_dispatch/middleware/public_exceptions.rb +14 -12
  116. data/lib/action_dispatch/middleware/reloader.rb +5 -3
  117. data/lib/action_dispatch/middleware/remote_ip.rb +87 -77
  118. data/lib/action_dispatch/middleware/request_id.rb +16 -10
  119. data/lib/action_dispatch/middleware/server_timing.rb +4 -2
  120. data/lib/action_dispatch/middleware/session/abstract_store.rb +2 -0
  121. data/lib/action_dispatch/middleware/session/cache_store.rb +30 -8
  122. data/lib/action_dispatch/middleware/session/cookie_store.rb +27 -26
  123. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +7 -3
  124. data/lib/action_dispatch/middleware/show_exceptions.rb +16 -16
  125. data/lib/action_dispatch/middleware/ssl.rb +53 -40
  126. data/lib/action_dispatch/middleware/stack.rb +11 -10
  127. data/lib/action_dispatch/middleware/static.rb +33 -31
  128. data/lib/action_dispatch/middleware/templates/rescues/_copy_button.html.erb +1 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +3 -5
  130. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +9 -5
  131. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +1 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +1 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +4 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +3 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +50 -0
  136. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +1 -0
  137. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -0
  138. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +1 -0
  139. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -0
  140. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -0
  141. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +1 -1
  142. data/lib/action_dispatch/railtie.rb +23 -3
  143. data/lib/action_dispatch/request/session.rb +24 -21
  144. data/lib/action_dispatch/request/utils.rb +11 -3
  145. data/lib/action_dispatch/routing/endpoint.rb +2 -0
  146. data/lib/action_dispatch/routing/inspector.rb +85 -60
  147. data/lib/action_dispatch/routing/mapper.rb +1031 -851
  148. data/lib/action_dispatch/routing/polymorphic_routes.rb +69 -62
  149. data/lib/action_dispatch/routing/redirection.rb +47 -39
  150. data/lib/action_dispatch/routing/route_set.rb +79 -56
  151. data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
  152. data/lib/action_dispatch/routing/url_for.rb +130 -125
  153. data/lib/action_dispatch/routing.rb +150 -148
  154. data/lib/action_dispatch/structured_event_subscriber.rb +20 -0
  155. data/lib/action_dispatch/system_test_case.rb +91 -81
  156. data/lib/action_dispatch/system_testing/browser.rb +16 -23
  157. data/lib/action_dispatch/system_testing/driver.rb +2 -0
  158. data/lib/action_dispatch/system_testing/server.rb +2 -0
  159. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +34 -23
  160. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
  161. data/lib/action_dispatch/testing/assertion_response.rb +9 -7
  162. data/lib/action_dispatch/testing/assertions/response.rb +52 -25
  163. data/lib/action_dispatch/testing/assertions/routing.rb +168 -87
  164. data/lib/action_dispatch/testing/assertions.rb +2 -0
  165. data/lib/action_dispatch/testing/integration.rb +233 -223
  166. data/lib/action_dispatch/testing/request_encoder.rb +11 -9
  167. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
  168. data/lib/action_dispatch/testing/test_process.rb +11 -8
  169. data/lib/action_dispatch/testing/test_request.rb +3 -1
  170. data/lib/action_dispatch/testing/test_response.rb +27 -26
  171. data/lib/action_dispatch.rb +36 -32
  172. data/lib/action_pack/gem_version.rb +6 -4
  173. data/lib/action_pack/version.rb +3 -1
  174. data/lib/action_pack.rb +17 -16
  175. metadata +36 -32
  176. data/lib/action_dispatch/journey/parser.y +0 -50
  177. data/lib/action_dispatch/journey/parser_extras.rb +0 -31
@@ -1,29 +1,102 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "uri"
4
6
  require "active_support/core_ext/hash/indifferent_access"
5
7
  require "active_support/core_ext/string/access"
8
+ require "active_support/core_ext/module/redefine_method"
6
9
  require "action_controller/metal/exceptions"
7
10
 
8
11
  module ActionDispatch
9
12
  module Assertions
10
- # Suite of assertions to test routes generated by \Rails and the handling of requests made to them.
13
+ # Suite of assertions to test routes generated by Rails and the handling of
14
+ # requests made to them.
11
15
  module RoutingAssertions
12
16
  extend ActiveSupport::Concern
13
17
 
18
+ module WithIntegrationRouting # :nodoc:
19
+ extend ActiveSupport::Concern
20
+
21
+ module ClassMethods
22
+ def with_routing(&block)
23
+ old_routes = nil
24
+ old_routes_call_method = nil
25
+ old_integration_session = nil
26
+
27
+ setup do
28
+ old_routes = initialize_lazy_routes(app.routes)
29
+ old_routes_call_method = old_routes.method(:call)
30
+ old_integration_session = integration_session
31
+ create_routes(&block)
32
+ end
33
+
34
+ teardown do
35
+ reset_routes(old_routes, old_routes_call_method, old_integration_session)
36
+ end
37
+ end
38
+ end
39
+
40
+ def with_routing(&block)
41
+ old_routes = initialize_lazy_routes(app.routes)
42
+ old_routes_call_method = old_routes.method(:call)
43
+ old_integration_session = integration_session
44
+ create_routes(&block)
45
+ ensure
46
+ reset_routes(old_routes, old_routes_call_method, old_integration_session)
47
+ end
48
+
49
+ private
50
+ def initialize_lazy_routes(routes)
51
+ if defined?(Rails::Engine::LazyRouteSet) && routes.is_a?(Rails::Engine::LazyRouteSet)
52
+ routes.tap(&:routes)
53
+ else
54
+ routes
55
+ end
56
+ end
57
+
58
+ def create_routes
59
+ app = self.app
60
+ routes = ActionDispatch::Routing::RouteSet.new
61
+
62
+ @original_routes ||= app.routes
63
+ @original_routes.singleton_class.redefine_method(:call, &routes.method(:call))
64
+
65
+ https = integration_session.https?
66
+ host = integration_session.host
67
+
68
+ app.instance_variable_set(:@routes, routes)
69
+ @integration_session = Class.new(ActionDispatch::Integration::Session) do
70
+ include app.routes.url_helpers
71
+ include app.routes.mounted_helpers
72
+ end.new(app)
73
+ @integration_session.https! https
74
+ @integration_session.host! host
75
+ @routes = routes
76
+
77
+ yield routes
78
+ end
79
+
80
+ def reset_routes(old_routes, old_routes_call_method, old_integration_session)
81
+ app.instance_variable_set(:@routes, old_routes)
82
+ @original_routes.singleton_class.redefine_method(:call, &old_routes_call_method)
83
+ @integration_session = old_integration_session
84
+ @routes = old_routes
85
+ end
86
+ end
87
+
14
88
  module ClassMethods
15
- # A helper to make it easier to test different route configurations.
16
- # This method temporarily replaces @routes with a new RouteSet instance
17
- # before each test.
89
+ # A helper to make it easier to test different route configurations. This method
90
+ # temporarily replaces @routes with a new RouteSet instance before each test.
18
91
  #
19
- # The new instance is yielded to the passed block. Typically the block
20
- # will create some routes using <tt>set.draw { match ... }</tt>:
92
+ # The new instance is yielded to the passed block. Typically the block will
93
+ # create some routes using `set.draw { match ... }`:
21
94
  #
22
- # with_routing do |set|
23
- # set.draw do
24
- # resources :users
95
+ # with_routing do |set|
96
+ # set.draw do
97
+ # resources :users
98
+ # end
25
99
  # end
26
- # end
27
100
  #
28
101
  def with_routing(&block)
29
102
  old_routes, old_controller = nil
@@ -44,36 +117,62 @@ module ActionDispatch
44
117
  super
45
118
  end
46
119
 
47
- # Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
48
- # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
120
+ # A helper to make it easier to test different route configurations. This method
121
+ # temporarily replaces @routes with a new RouteSet instance.
122
+ #
123
+ # The new instance is yielded to the passed block. Typically the block will
124
+ # create some routes using `set.draw { match ... }`:
125
+ #
126
+ # with_routing do |set|
127
+ # set.draw do
128
+ # resources :users
129
+ # end
130
+ # assert_equal "/users", users_path
131
+ # end
49
132
  #
50
- # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
51
- # requiring a specific HTTP method. The hash should contain a +:path+ with the incoming request path
52
- # and a +:method+ containing the required HTTP verb.
133
+ def with_routing(config = nil, &block)
134
+ old_routes, old_controller = @routes, @controller
135
+ create_routes(config, &block)
136
+ ensure
137
+ reset_routes(old_routes, old_controller)
138
+ end
139
+
140
+ # Asserts that the routing of the given `path` was handled correctly and that
141
+ # the parsed options (given in the `expected_options` hash) match `path`.
142
+ # Basically, it asserts that Rails recognizes the route given by
143
+ # `expected_options`.
53
144
  #
54
- # # Asserts that POSTing to /items will call the create action on ItemsController
55
- # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
145
+ # Pass a hash in the second argument (`path`) to specify the request method.
146
+ # This is useful for routes requiring a specific HTTP method. The hash should
147
+ # contain a `:path` with the incoming request path and a `:method` containing
148
+ # the required HTTP verb.
56
149
  #
57
- # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
58
- # to assert that values in the query string will end up in the params hash correctly. To test query strings you must use the extras
59
- # argument because appending the query string on the path directly will not work. For example:
150
+ # # Asserts that POSTing to /items will call the create action on ItemsController
151
+ # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
60
152
  #
61
- # # Asserts that a path of '/items/list/1?view=print' returns the correct options
62
- # assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
153
+ # You can also pass in `extras` with a hash containing URL parameters that would
154
+ # normally be in the query string. This can be used to assert that values in the
155
+ # query string will end up in the params hash correctly. To test query strings
156
+ # you must use the extras argument because appending the query string on the
157
+ # path directly will not work. For example:
63
158
  #
64
- # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
159
+ # # Asserts that a path of '/items/list/1?view=print' returns the correct options
160
+ # assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
65
161
  #
66
- # # Check the default route (i.e., the index action)
67
- # assert_recognizes({controller: 'items', action: 'index'}, 'items')
162
+ # The `message` parameter allows you to pass in an error message that is
163
+ # displayed upon failure.
68
164
  #
69
- # # Test a specific action
70
- # assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
165
+ # # Check the default route (i.e., the index action)
166
+ # assert_recognizes({controller: 'items', action: 'index'}, 'items')
71
167
  #
72
- # # Test an action with a parameter
73
- # assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
168
+ # # Test a specific action
169
+ # assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
74
170
  #
75
- # # Test a custom route
76
- # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
171
+ # # Test an action with a parameter
172
+ # assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
173
+ #
174
+ # # Test a custom route
175
+ # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
77
176
  def assert_recognizes(expected_options, path, extras = {}, msg = nil)
78
177
  if path.is_a?(Hash) && path[:method].to_s == "all"
79
178
  [:get, :post, :put, :delete].each do |method|
@@ -95,23 +194,25 @@ module ActionDispatch
95
194
  end
96
195
  end
97
196
 
98
- # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
99
- # The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
100
- # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
197
+ # Asserts that the provided options can be used to generate the provided path.
198
+ # This is the inverse of `assert_recognizes`. The `extras` parameter is used to
199
+ # tell the request the names and values of additional request parameters that
200
+ # would be in a query string. The `message` parameter allows you to specify a
201
+ # custom error message for assertion failures.
101
202
  #
102
- # The +defaults+ parameter is unused.
203
+ # The `defaults` parameter is unused.
103
204
  #
104
- # # Asserts that the default action is generated for a route with no action
105
- # assert_generates "/items", controller: "items", action: "index"
205
+ # # Asserts that the default action is generated for a route with no action
206
+ # assert_generates "/items", controller: "items", action: "index"
106
207
  #
107
- # # Tests that the list action is properly routed
108
- # assert_generates "/items/list", controller: "items", action: "list"
208
+ # # Tests that the list action is properly routed
209
+ # assert_generates "/items/list", controller: "items", action: "list"
109
210
  #
110
- # # Tests the generation of a route with a parameter
111
- # assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
211
+ # # Tests the generation of a route with a parameter
212
+ # assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
112
213
  #
113
- # # Asserts that the generated route gives us our custom route
114
- # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
214
+ # # Asserts that the generated route gives us our custom route
215
+ # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
115
216
  def assert_generates(expected_path, options, defaults = {}, extras = {}, message = nil)
116
217
  if expected_path.include?("://")
117
218
  fail_on(URI::InvalidURIError, message) do
@@ -134,27 +235,28 @@ module ActionDispatch
134
235
  assert_equal(expected_path, generated_path, msg)
135
236
  end
136
237
 
137
- # Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
138
- # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
139
- # and +assert_generates+ into one step.
238
+ # Asserts that path and options match both ways; in other words, it verifies
239
+ # that `path` generates `options` and then that `options` generates `path`. This
240
+ # essentially combines `assert_recognizes` and `assert_generates` into one step.
140
241
  #
141
- # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
142
- # +message+ parameter allows you to specify a custom error message to display upon failure.
242
+ # The `extras` hash allows you to specify options that would normally be
243
+ # provided as a query string to the action. The `message` parameter allows you
244
+ # to specify a custom error message to display upon failure.
143
245
  #
144
- # # Asserts a basic route: a controller with the default action (index)
145
- # assert_routing '/home', controller: 'home', action: 'index'
246
+ # # Asserts a basic route: a controller with the default action (index)
247
+ # assert_routing '/home', controller: 'home', action: 'index'
146
248
  #
147
- # # Test a route generated with a specific controller, action, and parameter (id)
148
- # assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
249
+ # # Test a route generated with a specific controller, action, and parameter (id)
250
+ # assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
149
251
  #
150
- # # Asserts a basic route (controller + default action), with an error message if it fails
151
- # assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
252
+ # # Asserts a basic route (controller + default action), with an error message if it fails
253
+ # assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
152
254
  #
153
- # # Tests a route, providing a defaults hash
154
- # assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
255
+ # # Tests a route, providing a defaults hash
256
+ # assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
155
257
  #
156
- # # Tests a route with an HTTP method
157
- # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
258
+ # # Tests a route with an HTTP method
259
+ # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
158
260
  def assert_routing(path, options, defaults = {}, extras = {}, message = nil)
159
261
  assert_recognizes(options, path, extras, message)
160
262
 
@@ -167,40 +269,19 @@ module ActionDispatch
167
269
  assert_generates(path.is_a?(Hash) ? path[:path] : path, generate_options, defaults, extras, message)
168
270
  end
169
271
 
170
- # A helper to make it easier to test different route configurations.
171
- # This method temporarily replaces @routes with a new RouteSet instance.
172
- #
173
- # The new instance is yielded to the passed block. Typically the block
174
- # will create some routes using <tt>set.draw { match ... }</tt>:
175
- #
176
- # with_routing do |set|
177
- # set.draw do
178
- # resources :users
179
- # end
180
- # assert_equal "/users", users_path
181
- # end
182
- #
183
- def with_routing(&block)
184
- old_routes, old_controller = @routes, @controller
185
- create_routes(&block)
186
- ensure
187
- reset_routes(old_routes, old_controller)
188
- end
189
-
190
272
  # ROUTES TODO: These assertions should really work in an integration context
191
- def method_missing(selector, *args, &block)
192
- if defined?(@controller) && @controller && defined?(@routes) && @routes && @routes.named_routes.route_defined?(selector)
193
- @controller.public_send(selector, *args, &block)
273
+ def method_missing(selector, ...)
274
+ if @controller && @routes&.named_routes&.route_defined?(selector)
275
+ @controller.public_send(selector, ...)
194
276
  else
195
277
  super
196
278
  end
197
279
  end
198
- ruby2_keywords(:method_missing)
199
280
 
200
281
  private
201
- def create_routes
202
- @routes = ActionDispatch::Routing::RouteSet.new
203
- if defined?(@controller) && @controller
282
+ def create_routes(config = nil)
283
+ @routes = ActionDispatch::Routing::RouteSet.new(config || ActionDispatch::Routing::RouteSet::DEFAULT_CONFIG)
284
+ if @controller
204
285
  @controller = @controller.clone
205
286
  _routes = @routes
206
287
 
@@ -224,7 +305,7 @@ module ActionDispatch
224
305
 
225
306
  def reset_routes(old_routes, old_controller)
226
307
  @routes = old_routes
227
- if defined?(@controller) && @controller
308
+ if @controller
228
309
  @controller = old_controller
229
310
  end
230
311
  end
@@ -267,7 +348,7 @@ module ActionDispatch
267
348
  def fail_on(exception_class, message)
268
349
  yield
269
350
  rescue exception_class => e
270
- raise Minitest::Assertion, message || e.message
351
+ flunk(message || e.message)
271
352
  end
272
353
  end
273
354
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "rails-dom-testing"
4
6
  require "action_dispatch/testing/assertions/response"
5
7
  require "action_dispatch/testing/assertions/routing"