diff options
author | Matthew Draper <matthew@trebex.net> | 2016-06-01 08:15:48 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-06-01 09:03:24 +0930 |
commit | 6d4ac2726f56c33677867178e2e01e5237df780a (patch) | |
tree | 75f140d3f8ed6e6656390b0867829b59a0e1415f /actionpack/lib | |
parent | c4cb6862babd2665a65056e205c2a5fd17a5d99d (diff) | |
download | rails-6d4ac2726f56c33677867178e2e01e5237df780a.tar.gz rails-6d4ac2726f56c33677867178e2e01e5237df780a.tar.bz2 rails-6d4ac2726f56c33677867178e2e01e5237df780a.zip |
Clean up the test request/response even after an exception
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index ed2edcbe06..b1b3e87934 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -527,34 +527,37 @@ module ActionController @request.set_header k, @controller.config.relative_url_root end - @controller.recycle! - @controller.dispatch(action, @request, @response) - @request = @controller.request - @response = @controller.response - - @request.delete_header 'HTTP_COOKIE' + begin + @controller.recycle! + @controller.dispatch(action, @request, @response) + ensure + @request = @controller.request + @response = @controller.response + + @request.delete_header 'HTTP_COOKIE' + + if @request.have_cookie_jar? + unless @request.cookie_jar.committed? + @request.cookie_jar.write(@response) + self.cookies.update(@request.cookie_jar.instance_variable_get(:@cookies)) + end + end + @response.prepare! - if @request.have_cookie_jar? - unless @request.cookie_jar.committed? - @request.cookie_jar.write(@response) - self.cookies.update(@request.cookie_jar.instance_variable_get(:@cookies)) + if flash_value = @request.flash.to_session_value + @request.session['flash'] = flash_value + else + @request.session.delete('flash') end - end - @response.prepare! - if flash_value = @request.flash.to_session_value - @request.session['flash'] = flash_value - else - @request.session.delete('flash') - end + if xhr + @request.delete_header 'HTTP_X_REQUESTED_WITH' + @request.delete_header 'HTTP_ACCEPT' + end + @request.query_string = '' - if xhr - @request.delete_header 'HTTP_X_REQUESTED_WITH' - @request.delete_header 'HTTP_ACCEPT' + @response.sent! end - @request.query_string = '' - - @response.sent! @response end |