Skip to content

Commit

Permalink
Controller, response, and request should all refer to same session, e…
Browse files Browse the repository at this point in the history
…ven after a call to session_reset [rails#1823 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
smtlaissezfaire authored and josh committed Jan 30, 2009
1 parent 1b79683 commit 2dedb5b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
23 changes: 19 additions & 4 deletions actionpack/lib/action_controller/test_process.rb
Expand Up @@ -15,7 +15,7 @@ def initialize
end

def reset_session
@session = TestSession.new
@session.reset
end

# Wraps raw_post in a StringIO.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions actionpack/test/controller/test_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2dedb5b

Please sign in to comment.