mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
a351149e80
Commit 4f2cd3e9
introduced a bug by reordering the call to
`@controller.recycle!` above the call to `build_request_uri`. The
impact of this was that the `@_url_options` cache ends up not being
reset between building a request URI (occurring within the test
controller) and the firing of the actual request.
We encountered this bug because we had the following setup:
class MinimumReproducibleController < ActionController::Base
before_filter { @param = 'param' }
def index
render text: url_for(params)
end
def default_url_options
{ custom_opt: @param }
end
end
def test_index
get :index # builds url, then fires actual request
end
The first step in `get :index` in the test suite would populate the
@_url_options cache. The subsequent call to `url_for` inside of the
controller action would then utilize the uncleared cache, thus never
calling the now-updated default_url_options.
This commit fixes this bug calling recycle! twice, and removes a call
to set response_body, which should no longer be needed since we're
recycling the request object explicitly.
31 lines
706 B
Ruby
31 lines
706 B
Ruby
module ActionController
|
|
module Testing
|
|
extend ActiveSupport::Concern
|
|
|
|
include RackDelegation
|
|
|
|
# TODO : Rewrite tests using controller.headers= to use Rack env
|
|
def headers=(new_headers)
|
|
@_response ||= ActionDispatch::Response.new
|
|
@_response.headers.replace(new_headers)
|
|
end
|
|
|
|
# Behavior specific to functional tests
|
|
module Functional # :nodoc:
|
|
def set_response!(request)
|
|
end
|
|
|
|
def recycle!
|
|
@_url_options = nil
|
|
self.formats = nil
|
|
self.params = nil
|
|
end
|
|
end
|
|
|
|
module ClassMethods
|
|
def before_filters
|
|
_process_action_callbacks.find_all{|x| x.kind == :before}.map{|x| x.name}
|
|
end
|
|
end
|
|
end
|
|
end
|