commit f71472deeef77d592ca6cb1bd52cdb481bf3d993 Author: Scott Taylor Date: Thu Jan 29 16:00:00 2009 -0500 Bug Fix: Controller, response, and request should all refer to same session, even after a call to session_reset diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index ea17363..4b5fc3a 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -15,7 +15,7 @@ module ActionController #:nodoc: end def reset_session - @session = TestSession.new + @session.reset end # Wraps raw_post in a StringIO. @@ -284,9 +284,13 @@ module ActionController #:nodoc: attr_accessor :session_id def initialize(attributes = nil) - @session_id = '' - attributes ||= {} - replace(attributes.stringify_keys) + reset_session_id + replace_attributes(attributes) + end + + def reset + reset_session_id + replace_attributes({ }) end def data @@ -322,6 +326,17 @@ module ActionController #:nodoc: def close ActiveSupport::Deprecation.warn('sessions should no longer be closed', caller) end + + private + + def reset_session_id + @session_id = '' + end + + def replace_attributes(attributes = nil) + attributes ||= {} + replace(attributes.stringify_keys) + end end # Essentially generates a modified Tempfile object similar to the object diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index ee7b8ad..65c894c 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -23,6 +23,11 @@ class TestTest < ActionController::TestCase render :text => 'Success' end + def reset_the_session + reset_session + render :text => 'ignore me' + end + def render_raw_post raise ActiveSupport::TestCase::Assertion, "#raw_post is blank" if request.raw_post.blank? render :text => request.raw_post @@ -171,6 +176,24 @@ XML assert_equal 'value2', session[:symbol] end + def test_session_is_cleared_from_controller_after_reset_session + process :set_session + process :reset_the_session + assert_equal Hash.new, @controller.session.to_hash + end + + def test_session_is_cleared_from_response_after_reset_session + process :set_session + process :reset_the_session + assert_equal Hash.new, @response.session.to_hash + end + + def test_session_is_cleared_from_request_after_reset_session + process :set_session + process :reset_the_session + assert_equal Hash.new, @request.session.to_hash + end + def test_process_with_request_uri_with_no_params process :test_uri assert_equal "/test_test/test/test_uri", @response.body