提交 6d4ac272 编写于 作者: M Matthew Draper

Clean up the test request/response even after an exception

上级 c4cb6862
......@@ -527,8 +527,10 @@ def process(action, *args)
@request.set_header k, @controller.config.relative_url_root
end
begin
@controller.recycle!
@controller.dispatch(action, @request, @response)
ensure
@request = @controller.request
@response = @controller.response
......@@ -555,6 +557,7 @@ def process(action, *args)
@request.query_string = ''
@response.sent!
end
@response
end
......
......@@ -154,6 +154,10 @@ def test_with_body
render html: '<body class="foo"></body>'.html_safe
end
def boom
raise 'boom!'
end
private
def generate_url(opts)
......@@ -981,6 +985,26 @@ def test_redirect_url_only_cares_about_location_header
assert_redirected_to 'created resource'
end
end
def test_exception_in_action_reaches_test
assert_raise(RuntimeError) do
process :boom, method: "GET"
end
end
def test_request_state_is_cleared_after_exception
assert_raise(RuntimeError) do
process :boom,
method: "GET",
params: { q: 'test1' }
end
process :test_query_string,
method: "GET",
params: { q: 'test2' }
assert_equal "q=test2", @response.body
end
end
class ResponseDefaultHeadersTest < ActionController::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册