Browse files

refactor Redirecting so we do not need a controller instance

  • Loading branch information...
1 parent 3dfcae6 commit 2090615d39c071c9eb25e715275eb79f3f9b6266 @tenderlove tenderlove committed Aug 6, 2014
View
8 actionpack/lib/action_controller/metal/redirecting.rb
@@ -72,11 +72,11 @@ def redirect_to(options = {}, response_status = {}) #:doc:
raise AbstractController::DoubleRenderError if response_body
self.status = _extract_redirect_to_status(options, response_status)
- self.location = _compute_redirect_to_location(options)
+ self.location = _compute_redirect_to_location(request, options)
self.response_body = "<html><body>You are being <a href=\"#{ERB::Util.unwrapped_html_escape(location)}\">redirected</a>.</body></html>"
end
- def _compute_redirect_to_location(options) #:nodoc:
+ def _compute_redirect_to_location(request, options) #:nodoc:
case options
# The scheme name consist of a letter followed by any combination of
# letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
@@ -90,11 +90,13 @@ def _compute_redirect_to_location(options) #:nodoc:
when :back
request.headers["Referer"] or raise RedirectBackError
when Proc
- _compute_redirect_to_location options.call
+ _compute_redirect_to_location request, options.call
else
url_for(options)
end.delete("\0\r\n")
end
+ module_function :_compute_redirect_to_location
+ public :_compute_redirect_to_location
private
def _extract_redirect_to_status(options, response_status)
View
9 actionpack/lib/action_dispatch/testing/assertions/response.rb
@@ -73,13 +73,8 @@ def normalize_argument_to_redirection(fragment)
if Regexp === fragment
fragment
else
- handle = @controller || Class.new(ActionController::Metal) do
- include ActionController::Redirecting
- def initialize(request)
- @_request = request
- end
- end.new(@request)
- handle._compute_redirect_to_location(fragment)
+ handle = @controller || ActionController::Redirecting
+ handle._compute_redirect_to_location(@request, fragment)
end
end
end

0 comments on commit 2090615

Please sign in to comment.