actionpack 4.0.1 → 4.2.11.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (241) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +402 -1173
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +7 -7
  5. data/lib/abstract_controller/base.rb +39 -7
  6. data/lib/abstract_controller/callbacks.rb +32 -53
  7. data/lib/abstract_controller/collector.rb +11 -1
  8. data/lib/abstract_controller/helpers.rb +26 -16
  9. data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
  10. data/lib/abstract_controller/rendering.rb +57 -127
  11. data/lib/abstract_controller/url_for.rb +1 -1
  12. data/lib/abstract_controller.rb +1 -2
  13. data/lib/action_controller/base.rb +19 -10
  14. data/lib/action_controller/caching/fragments.rb +7 -1
  15. data/lib/action_controller/caching.rb +2 -12
  16. data/lib/action_controller/log_subscriber.rb +29 -20
  17. data/lib/action_controller/metal/conditional_get.rb +37 -12
  18. data/lib/action_controller/metal/data_streaming.rb +1 -1
  19. data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
  20. data/lib/action_controller/metal/exceptions.rb +1 -1
  21. data/lib/action_controller/metal/flash.rb +17 -0
  22. data/lib/action_controller/metal/force_ssl.rb +2 -2
  23. data/lib/action_controller/metal/head.rb +8 -6
  24. data/lib/action_controller/metal/helpers.rb +6 -2
  25. data/lib/action_controller/metal/http_authentication.rb +45 -23
  26. data/lib/action_controller/metal/instrumentation.rb +9 -6
  27. data/lib/action_controller/metal/live.rb +173 -20
  28. data/lib/action_controller/metal/mime_responds.rb +127 -232
  29. data/lib/action_controller/metal/params_wrapper.rb +16 -9
  30. data/lib/action_controller/metal/rack_delegation.rb +1 -1
  31. data/lib/action_controller/metal/redirecting.rb +34 -26
  32. data/lib/action_controller/metal/renderers.rb +39 -12
  33. data/lib/action_controller/metal/rendering.rb +41 -14
  34. data/lib/action_controller/metal/request_forgery_protection.rb +147 -19
  35. data/lib/action_controller/metal/streaming.rb +19 -21
  36. data/lib/action_controller/metal/strong_parameters.rb +166 -22
  37. data/lib/action_controller/metal/testing.rb +0 -1
  38. data/lib/action_controller/metal/url_for.rb +11 -12
  39. data/lib/action_controller/metal.rb +14 -8
  40. data/lib/action_controller/model_naming.rb +1 -1
  41. data/lib/action_controller/railtie.rb +5 -1
  42. data/lib/action_controller/test_case.rb +160 -94
  43. data/lib/action_controller.rb +2 -18
  44. data/lib/action_dispatch/http/cache.rb +5 -4
  45. data/lib/action_dispatch/http/filter_parameters.rb +2 -2
  46. data/lib/action_dispatch/http/filter_redirect.rb +5 -4
  47. data/lib/action_dispatch/http/headers.rb +46 -10
  48. data/lib/action_dispatch/http/mime_negotiation.rb +31 -4
  49. data/lib/action_dispatch/http/mime_type.rb +25 -26
  50. data/lib/action_dispatch/http/mime_types.rb +1 -0
  51. data/lib/action_dispatch/http/parameter_filter.rb +1 -1
  52. data/lib/action_dispatch/http/parameters.rb +25 -41
  53. data/lib/action_dispatch/http/request.rb +49 -32
  54. data/lib/action_dispatch/http/response.rb +127 -25
  55. data/lib/action_dispatch/http/upload.rb +9 -21
  56. data/lib/action_dispatch/http/url.rb +97 -70
  57. data/lib/action_dispatch/journey/formatter.rb +35 -19
  58. data/lib/action_dispatch/journey/gtg/builder.rb +3 -3
  59. data/lib/action_dispatch/journey/gtg/simulator.rb +10 -7
  60. data/lib/action_dispatch/journey/gtg/transition_table.rb +23 -33
  61. data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
  62. data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
  63. data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -5
  64. data/lib/action_dispatch/journey/nodes/node.rb +4 -0
  65. data/lib/action_dispatch/journey/parser.rb +51 -59
  66. data/lib/action_dispatch/journey/parser.y +12 -10
  67. data/lib/action_dispatch/journey/path/pattern.rb +16 -19
  68. data/lib/action_dispatch/journey/route.rb +8 -19
  69. data/lib/action_dispatch/journey/router/strexp.rb +9 -6
  70. data/lib/action_dispatch/journey/router/utils.rb +54 -18
  71. data/lib/action_dispatch/journey/router.rb +53 -75
  72. data/lib/action_dispatch/journey/routes.rb +4 -0
  73. data/lib/action_dispatch/journey/scanner.rb +5 -5
  74. data/lib/action_dispatch/journey/visitors.rb +81 -60
  75. data/lib/action_dispatch/journey/visualizer/fsm.css +0 -4
  76. data/lib/action_dispatch/journey/visualizer/index.html.erb +2 -2
  77. data/lib/action_dispatch/middleware/callbacks.rb +7 -7
  78. data/lib/action_dispatch/middleware/cookies.rb +119 -43
  79. data/lib/action_dispatch/middleware/debug_exceptions.rb +32 -13
  80. data/lib/action_dispatch/middleware/exception_wrapper.rb +60 -20
  81. data/lib/action_dispatch/middleware/flash.rb +37 -24
  82. data/lib/action_dispatch/middleware/params_parser.rb +2 -2
  83. data/lib/action_dispatch/middleware/public_exceptions.rb +12 -3
  84. data/lib/action_dispatch/middleware/reloader.rb +11 -2
  85. data/lib/action_dispatch/middleware/remote_ip.rb +40 -54
  86. data/lib/action_dispatch/middleware/request_id.rb +1 -1
  87. data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
  88. data/lib/action_dispatch/middleware/session/cookie_store.rb +8 -7
  89. data/lib/action_dispatch/middleware/show_exceptions.rb +6 -2
  90. data/lib/action_dispatch/middleware/ssl.rb +10 -7
  91. data/lib/action_dispatch/middleware/static.rb +79 -23
  92. data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
  93. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  94. data/lib/action_dispatch/middleware/templates/rescues/_source.erb +21 -19
  95. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  96. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  97. data/lib/action_dispatch/middleware/templates/rescues/{diagnostics.erb → diagnostics.html.erb} +1 -1
  98. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  99. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +6 -0
  100. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  101. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  102. data/lib/action_dispatch/middleware/templates/rescues/{routing_error.erb → routing_error.html.erb} +3 -1
  103. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  104. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  105. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  106. data/lib/action_dispatch/middleware/templates/rescues/{unknown_action.erb → unknown_action.html.erb} +1 -1
  107. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  108. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +120 -64
  109. data/lib/action_dispatch/railtie.rb +5 -2
  110. data/lib/action_dispatch/request/session.rb +12 -0
  111. data/lib/action_dispatch/request/utils.rb +35 -0
  112. data/lib/action_dispatch/routing/endpoint.rb +10 -0
  113. data/lib/action_dispatch/routing/inspector.rb +11 -17
  114. data/lib/action_dispatch/routing/mapper.rb +519 -312
  115. data/lib/action_dispatch/routing/polymorphic_routes.rb +204 -79
  116. data/lib/action_dispatch/routing/redirection.rb +51 -26
  117. data/lib/action_dispatch/routing/route_set.rb +331 -206
  118. data/lib/action_dispatch/routing/routes_proxy.rb +5 -4
  119. data/lib/action_dispatch/routing/url_for.rb +19 -5
  120. data/lib/action_dispatch/routing.rb +9 -6
  121. data/lib/action_dispatch/testing/assertions/dom.rb +2 -26
  122. data/lib/action_dispatch/testing/assertions/response.rb +9 -15
  123. data/lib/action_dispatch/testing/assertions/routing.rb +22 -22
  124. data/lib/action_dispatch/testing/assertions/selector.rb +2 -429
  125. data/lib/action_dispatch/testing/assertions/tag.rb +2 -134
  126. data/lib/action_dispatch/testing/assertions.rb +11 -7
  127. data/lib/action_dispatch/testing/integration.rb +31 -29
  128. data/lib/action_dispatch/testing/test_request.rb +1 -1
  129. data/lib/action_dispatch/testing/test_response.rb +1 -5
  130. data/lib/action_dispatch.rb +5 -8
  131. data/lib/action_pack/gem_version.rb +15 -0
  132. data/lib/action_pack/version.rb +4 -7
  133. data/lib/action_pack.rb +1 -1
  134. metadata +77 -159
  135. data/lib/abstract_controller/layouts.rb +0 -423
  136. data/lib/abstract_controller/view_paths.rb +0 -96
  137. data/lib/action_controller/deprecated/integration_test.rb +0 -5
  138. data/lib/action_controller/deprecated.rb +0 -7
  139. data/lib/action_controller/metal/responder.rb +0 -287
  140. data/lib/action_controller/record_identifier.rb +0 -31
  141. data/lib/action_controller/vendor/html-scanner.rb +0 -5
  142. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -24
  143. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -7
  144. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -43
  145. data/lib/action_view/base.rb +0 -201
  146. data/lib/action_view/buffers.rb +0 -49
  147. data/lib/action_view/context.rb +0 -36
  148. data/lib/action_view/dependency_tracker.rb +0 -93
  149. data/lib/action_view/digestor.rb +0 -113
  150. data/lib/action_view/flows.rb +0 -76
  151. data/lib/action_view/helpers/active_model_helper.rb +0 -49
  152. data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
  153. data/lib/action_view/helpers/asset_url_helper.rb +0 -355
  154. data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
  155. data/lib/action_view/helpers/cache_helper.rb +0 -196
  156. data/lib/action_view/helpers/capture_helper.rb +0 -216
  157. data/lib/action_view/helpers/controller_helper.rb +0 -25
  158. data/lib/action_view/helpers/csrf_helper.rb +0 -30
  159. data/lib/action_view/helpers/date_helper.rb +0 -1083
  160. data/lib/action_view/helpers/debug_helper.rb +0 -39
  161. data/lib/action_view/helpers/form_helper.rb +0 -1880
  162. data/lib/action_view/helpers/form_options_helper.rb +0 -838
  163. data/lib/action_view/helpers/form_tag_helper.rb +0 -785
  164. data/lib/action_view/helpers/javascript_helper.rb +0 -117
  165. data/lib/action_view/helpers/number_helper.rb +0 -441
  166. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  167. data/lib/action_view/helpers/record_tag_helper.rb +0 -106
  168. data/lib/action_view/helpers/rendering_helper.rb +0 -90
  169. data/lib/action_view/helpers/sanitize_helper.rb +0 -256
  170. data/lib/action_view/helpers/tag_helper.rb +0 -173
  171. data/lib/action_view/helpers/tags/base.rb +0 -148
  172. data/lib/action_view/helpers/tags/check_box.rb +0 -64
  173. data/lib/action_view/helpers/tags/checkable.rb +0 -16
  174. data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -44
  175. data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
  176. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
  177. data/lib/action_view/helpers/tags/collection_select.rb +0 -28
  178. data/lib/action_view/helpers/tags/color_field.rb +0 -25
  179. data/lib/action_view/helpers/tags/date_field.rb +0 -13
  180. data/lib/action_view/helpers/tags/date_select.rb +0 -72
  181. data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
  182. data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
  183. data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
  184. data/lib/action_view/helpers/tags/email_field.rb +0 -8
  185. data/lib/action_view/helpers/tags/file_field.rb +0 -8
  186. data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
  187. data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
  188. data/lib/action_view/helpers/tags/label.rb +0 -66
  189. data/lib/action_view/helpers/tags/month_field.rb +0 -13
  190. data/lib/action_view/helpers/tags/number_field.rb +0 -18
  191. data/lib/action_view/helpers/tags/password_field.rb +0 -12
  192. data/lib/action_view/helpers/tags/radio_button.rb +0 -31
  193. data/lib/action_view/helpers/tags/range_field.rb +0 -8
  194. data/lib/action_view/helpers/tags/search_field.rb +0 -24
  195. data/lib/action_view/helpers/tags/select.rb +0 -40
  196. data/lib/action_view/helpers/tags/tel_field.rb +0 -8
  197. data/lib/action_view/helpers/tags/text_area.rb +0 -18
  198. data/lib/action_view/helpers/tags/text_field.rb +0 -29
  199. data/lib/action_view/helpers/tags/time_field.rb +0 -13
  200. data/lib/action_view/helpers/tags/time_select.rb +0 -8
  201. data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
  202. data/lib/action_view/helpers/tags/url_field.rb +0 -8
  203. data/lib/action_view/helpers/tags/week_field.rb +0 -13
  204. data/lib/action_view/helpers/tags.rb +0 -39
  205. data/lib/action_view/helpers/text_helper.rb +0 -443
  206. data/lib/action_view/helpers/translation_helper.rb +0 -107
  207. data/lib/action_view/helpers/url_helper.rb +0 -635
  208. data/lib/action_view/helpers.rb +0 -58
  209. data/lib/action_view/locale/en.yml +0 -56
  210. data/lib/action_view/log_subscriber.rb +0 -30
  211. data/lib/action_view/lookup_context.rb +0 -241
  212. data/lib/action_view/model_naming.rb +0 -12
  213. data/lib/action_view/path_set.rb +0 -77
  214. data/lib/action_view/railtie.rb +0 -43
  215. data/lib/action_view/record_identifier.rb +0 -84
  216. data/lib/action_view/renderer/abstract_renderer.rb +0 -47
  217. data/lib/action_view/renderer/partial_renderer.rb +0 -492
  218. data/lib/action_view/renderer/renderer.rb +0 -50
  219. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
  220. data/lib/action_view/renderer/template_renderer.rb +0 -96
  221. data/lib/action_view/routing_url_for.rb +0 -107
  222. data/lib/action_view/tasks/dependencies.rake +0 -17
  223. data/lib/action_view/template/error.rb +0 -138
  224. data/lib/action_view/template/handlers/builder.rb +0 -26
  225. data/lib/action_view/template/handlers/erb.rb +0 -146
  226. data/lib/action_view/template/handlers/raw.rb +0 -11
  227. data/lib/action_view/template/handlers.rb +0 -53
  228. data/lib/action_view/template/resolver.rb +0 -326
  229. data/lib/action_view/template/text.rb +0 -34
  230. data/lib/action_view/template/types.rb +0 -57
  231. data/lib/action_view/template.rb +0 -339
  232. data/lib/action_view/test_case.rb +0 -270
  233. data/lib/action_view/testing/resolvers.rb +0 -50
  234. data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
  235. data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
  236. data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
  237. data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
  238. data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
  239. data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
  240. data/lib/action_view/vendor/html-scanner.rb +0 -20
  241. data/lib/action_view.rb +0 -93
@@ -8,8 +8,9 @@ module ActionDispatch
8
8
  attr_accessor :scope, :routes
9
9
  alias :_routes :routes
10
10
 
11
- def initialize(routes, scope)
11
+ def initialize(routes, scope, helpers)
12
12
  @routes, @scope = routes, scope
13
+ @helpers = helpers
13
14
  end
14
15
 
15
16
  def url_options
@@ -19,16 +20,16 @@ module ActionDispatch
19
20
  end
20
21
 
21
22
  def respond_to?(method, include_private = false)
22
- super || routes.url_helpers.respond_to?(method)
23
+ super || @helpers.respond_to?(method)
23
24
  end
24
25
 
25
26
  def method_missing(method, *args)
26
- if routes.url_helpers.respond_to?(method)
27
+ if @helpers.respond_to?(method)
27
28
  self.class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
28
29
  def #{method}(*args)
29
30
  options = args.extract_options!
30
31
  args << url_options.merge((options || {}).symbolize_keys)
31
- routes.url_helpers.#{method}(*args)
32
+ @helpers.#{method}(*args)
32
33
  end
33
34
  RUBY
34
35
  send(method, *args)
@@ -20,7 +20,7 @@ module ActionDispatch
20
20
  #
21
21
  # <%= link_to('Click here', controller: 'users',
22
22
  # action: 'new', message: 'Welcome!') %>
23
- # # => "/users/new?message=Welcome%21"
23
+ # # => <a href="/users/new?message=Welcome%21">Click here</a>
24
24
  #
25
25
  # link_to, and all other functions that require URL generation functionality,
26
26
  # actually use ActionController::UrlFor under the hood. And in particular,
@@ -152,19 +152,27 @@ module ActionDispatch
152
152
  when nil
153
153
  _routes.url_for(url_options.symbolize_keys)
154
154
  when Hash
155
- _routes.url_for(options.symbolize_keys.reverse_merge!(url_options))
155
+ route_name = options.delete :use_route
156
+ _routes.url_for(options.symbolize_keys.reverse_merge!(url_options),
157
+ route_name)
156
158
  when String
157
159
  options
160
+ when Symbol
161
+ HelperMethodBuilder.url.handle_string_call self, options
162
+ when Array
163
+ components = options.dup
164
+ polymorphic_url(components, components.extract_options!)
165
+ when Class
166
+ HelperMethodBuilder.url.handle_class_call self, options
158
167
  else
159
- polymorphic_url(options)
168
+ HelperMethodBuilder.url.handle_model_call self, options
160
169
  end
161
170
  end
162
171
 
163
172
  protected
164
173
 
165
174
  def optimize_routes_generation?
166
- return @_optimized_routes if defined?(@_optimized_routes)
167
- @_optimized_routes = _routes.optimize_routes_generation? && default_url_options.empty?
175
+ _routes.optimize_routes_generation? && default_url_options.empty?
168
176
  end
169
177
 
170
178
  def _with_routes(routes)
@@ -177,6 +185,12 @@ module ActionDispatch
177
185
  def _routes_context
178
186
  self
179
187
  end
188
+
189
+ private
190
+
191
+ def _generate_paths_by_default
192
+ true
193
+ end
180
194
  end
181
195
  end
182
196
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require 'active_support/core_ext/object/to_param'
3
3
  require 'active_support/core_ext/regexp'
4
+ require 'active_support/dependencies/autoload'
4
5
 
5
6
  module ActionDispatch
6
7
  # The routing module provides URL rewriting in native Ruby. It's a way to
@@ -11,7 +12,7 @@ module ActionDispatch
11
12
  # Think of creating routes as drawing a map for your requests. The map tells
12
13
  # them where to go based on some predefined pattern:
13
14
  #
14
- # AppName::Application.routes.draw do
15
+ # Rails.application.routes.draw do
15
16
  # Pattern 1 tells some request to go to one place
16
17
  # Pattern 2 tell them to go to another
17
18
  # ...
@@ -246,11 +247,13 @@ module ActionDispatch
246
247
  # Target specific controllers by prefixing the command with <tt>CONTROLLER=x</tt>.
247
248
  #
248
249
  module Routing
249
- autoload :Mapper, 'action_dispatch/routing/mapper'
250
- autoload :RouteSet, 'action_dispatch/routing/route_set'
251
- autoload :RoutesProxy, 'action_dispatch/routing/routes_proxy'
252
- autoload :UrlFor, 'action_dispatch/routing/url_for'
253
- autoload :PolymorphicRoutes, 'action_dispatch/routing/polymorphic_routes'
250
+ extend ActiveSupport::Autoload
251
+
252
+ autoload :Mapper
253
+ autoload :RouteSet
254
+ autoload :RoutesProxy
255
+ autoload :UrlFor
256
+ autoload :PolymorphicRoutes
254
257
 
255
258
  SEPARATORS = %w( / . ? ) #:nodoc:
256
259
  HTTP_METHODS = [:get, :head, :post, :patch, :put, :delete, :options] #:nodoc:
@@ -1,27 +1,3 @@
1
- require 'action_view/vendor/html-scanner'
1
+ require 'active_support/deprecation'
2
2
 
3
- module ActionDispatch
4
- module Assertions
5
- module DomAssertions
6
- # \Test two HTML strings for equivalency (e.g., identical up to reordering of attributes)
7
- #
8
- # # assert that the referenced method generates the appropriate HTML string
9
- # assert_dom_equal '<a href="http://www.example.com">Apples</a>', link_to("Apples", "http://www.example.com")
10
- def assert_dom_equal(expected, actual, message = nil)
11
- expected_dom = HTML::Document.new(expected).root
12
- actual_dom = HTML::Document.new(actual).root
13
- assert_equal expected_dom, actual_dom, message
14
- end
15
-
16
- # The negated form of +assert_dom_equivalent+.
17
- #
18
- # # assert that the referenced method does not generate the specified HTML string
19
- # assert_dom_not_equal '<a href="http://www.example.com">Apples</a>', link_to("Oranges", "http://www.example.com")
20
- def assert_dom_not_equal(expected, actual, message = nil)
21
- expected_dom = HTML::Document.new(expected).root
22
- actual_dom = HTML::Document.new(actual).root
23
- assert_not_equal expected_dom, actual_dom, message
24
- end
25
- end
26
- end
27
- end
3
+ ActiveSupport::Deprecation.warn("ActionDispatch::Assertions::DomAssertions has been extracted to the rails-dom-testing gem.")
@@ -27,6 +27,9 @@ module ActionDispatch
27
27
  assert @response.send("#{type}?"), message
28
28
  else
29
29
  code = Rack::Utils::SYMBOL_TO_STATUS_CODE[type]
30
+ if code.nil?
31
+ raise ArgumentError, "Invalid response type :#{type}"
32
+ end
30
33
  assert_equal code, @response.response_code, message
31
34
  end
32
35
  else
@@ -67,21 +70,12 @@ module ActionDispatch
67
70
  end
68
71
 
69
72
  def normalize_argument_to_redirection(fragment)
70
- normalized = case fragment
71
- when Regexp
72
- fragment
73
- when %r{^\w[A-Za-z\d+.-]*:.*}
74
- fragment
75
- when String
76
- @request.protocol + @request.host_with_port + fragment
77
- when :back
78
- raise RedirectBackError unless refer = @request.headers["Referer"]
79
- refer
80
- else
81
- @controller.url_for(fragment)
82
- end
83
-
84
- normalized.respond_to?(:delete) ? normalized.delete("\0\r\n") : normalized
73
+ if Regexp === fragment
74
+ fragment
75
+ else
76
+ handle = @controller || ActionController::Redirecting
77
+ handle._compute_redirect_to_location(@request, fragment)
78
+ end
85
79
  end
86
80
  end
87
81
  end
@@ -38,18 +38,24 @@ module ActionDispatch
38
38
  # # Test a custom route
39
39
  # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
40
40
  def assert_recognizes(expected_options, path, extras={}, msg=nil)
41
- request = recognized_request_for(path, extras)
41
+ if path.is_a?(Hash) && path[:method].to_s == "all"
42
+ [:get, :post, :put, :delete].each do |method|
43
+ assert_recognizes(expected_options, path.merge(method: method), extras, msg)
44
+ end
45
+ else
46
+ request = recognized_request_for(path, extras, msg)
42
47
 
43
- expected_options = expected_options.clone
48
+ expected_options = expected_options.clone
44
49
 
45
- expected_options.stringify_keys!
50
+ expected_options.stringify_keys!
46
51
 
47
- msg = message(msg, "") {
48
- sprintf("The recognized options <%s> did not match <%s>, difference:",
49
- request.path_parameters, expected_options)
50
- }
52
+ msg = message(msg, "") {
53
+ sprintf("The recognized options <%s> did not match <%s>, difference:",
54
+ request.path_parameters, expected_options)
55
+ }
51
56
 
52
- assert_equal(expected_options, request.path_parameters, msg)
57
+ assert_equal(expected_options, request.path_parameters, msg)
58
+ end
53
59
  end
54
60
 
55
61
  # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
@@ -69,9 +75,9 @@ module ActionDispatch
69
75
  #
70
76
  # # Asserts that the generated route gives us our custom route
71
77
  # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
72
- def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
78
+ def assert_generates(expected_path, options, defaults={}, extras={}, message=nil)
73
79
  if expected_path =~ %r{://}
74
- fail_on(URI::InvalidURIError) do
80
+ fail_on(URI::InvalidURIError, message) do
75
81
  uri = URI.parse(expected_path)
76
82
  expected_path = uri.path.to_s.empty? ? "/" : uri.path
77
83
  end
@@ -144,12 +150,6 @@ module ActionDispatch
144
150
  old_controller, @controller = @controller, @controller.clone
145
151
  _routes = @routes
146
152
 
147
- # Unfortunately, there is currently an abstraction leak between AC::Base
148
- # and AV::Base which requires having the URL helpers in both AC and AV.
149
- # To do this safely at runtime for tests, we need to bump up the helper serial
150
- # to that the old AV subclass isn't cached.
151
- #
152
- # TODO: Make this unnecessary
153
153
  @controller.singleton_class.send(:include, _routes.url_helpers)
154
154
  @controller.view_context_class = Class.new(@controller.view_context_class) do
155
155
  include _routes.url_helpers
@@ -165,7 +165,7 @@ module ActionDispatch
165
165
 
166
166
  # ROUTES TODO: These assertions should really work in an integration context
167
167
  def method_missing(selector, *args, &block)
168
- if defined?(@controller) && @controller && @routes && @routes.named_routes.helpers.include?(selector)
168
+ if defined?(@controller) && @controller && defined?(@routes) && @routes && @routes.named_routes.route_defined?(selector)
169
169
  @controller.send(selector, *args, &block)
170
170
  else
171
171
  super
@@ -174,7 +174,7 @@ module ActionDispatch
174
174
 
175
175
  private
176
176
  # Recognizes the route for a given path.
177
- def recognized_request_for(path, extras = {})
177
+ def recognized_request_for(path, extras = {}, msg)
178
178
  if path.is_a?(Hash)
179
179
  method = path[:method]
180
180
  path = path[:path]
@@ -186,7 +186,7 @@ module ActionDispatch
186
186
  request = ActionController::TestRequest.new
187
187
 
188
188
  if path =~ %r{://}
189
- fail_on(URI::InvalidURIError) do
189
+ fail_on(URI::InvalidURIError, msg) do
190
190
  uri = URI.parse(path)
191
191
  request.env["rack.url_scheme"] = uri.scheme || "http"
192
192
  request.host = uri.host if uri.host
@@ -200,7 +200,7 @@ module ActionDispatch
200
200
 
201
201
  request.request_method = method if method
202
202
 
203
- params = fail_on(ActionController::RoutingError) do
203
+ params = fail_on(ActionController::RoutingError, msg) do
204
204
  @routes.recognize_path(path, { :method => method, :extras => extras })
205
205
  end
206
206
  request.path_parameters = params.with_indifferent_access
@@ -208,10 +208,10 @@ module ActionDispatch
208
208
  request
209
209
  end
210
210
 
211
- def fail_on(exception_class)
211
+ def fail_on(exception_class, message)
212
212
  yield
213
213
  rescue exception_class => e
214
- raise MiniTest::Assertion, e.message
214
+ raise Minitest::Assertion, message || e.message
215
215
  end
216
216
  end
217
217
  end