Skip to content
Browse files

Controller, response, and request should all refer to same session, e…

…ven after a call to session_reset [#1823 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
1 parent 1b79683 commit 2dedb5b03ab88a1c31068f71c8d4cad7c5a5d9ae @smtlaissezfaire smtlaissezfaire committed with josh
Showing with 42 additions and 4 deletions.
  1. +19 −4 actionpack/lib/action_controller/test_process.rb
  2. +23 −0 actionpack/test/controller/test_test.rb
View
23 actionpack/lib/action_controller/test_process.rb
@@ -15,7 +15,7 @@ def initialize
end
def reset_session
- @session = TestSession.new
+ @session.reset
end
# Wraps raw_post in a StringIO.
@@ -284,9 +284,13 @@ class TestSession < Hash #: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 @@ def delete(key = nil)
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
View
23 actionpack/test/controller/test_test.rb
@@ -23,6 +23,11 @@ def set_session
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 @@ def test_process_with_session_arg
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

0 comments on commit 2dedb5b

Please sign in to comment.
Something went wrong with that request. Please try again.