Skip to content

Commit

Permalink
Merged pull request rails#198 from robdimarco/2-3-stable.
Browse files Browse the repository at this point in the history
Patch for issue 6440 - Session Reset undefined method `destroy' for {}:Hash
  • Loading branch information
josevalim committed Apr 28, 2011
2 parents f424efe + 8ca8ac3 commit d793a56
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion actionpack/lib/action_controller/request.rb
Expand Up @@ -446,7 +446,9 @@ def session=(session) #:nodoc:
end end


def reset_session def reset_session
session.destroy if session # session may be a hash, if so, we do not want to call destroy
# fixes issue 6440
session.destroy if session and session.respond_to?(:destroy)
self.session = {} self.session = {}
end end


Expand Down
44 changes: 44 additions & 0 deletions actionpack/test/controller/session/cookie_store_test.rb
Expand Up @@ -42,6 +42,12 @@ def call_session_clear
head :ok head :ok
end end


def call_reset_session_twice
reset_session
reset_session
head :ok
end

def call_reset_session def call_reset_session
reset_session reset_session
head :ok head :ok
Expand Down Expand Up @@ -190,6 +196,44 @@ def test_doesnt_write_session_cookie_if_session_is_unchanged
end end
end end


def test_calling_session_reset_twice
with_test_route_set do
get '/set_session_value'
assert_response :success
session_payload = response.body
assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly",
headers['Set-Cookie']

get '/call_reset_session_twice'
assert_response :success
assert_not_equal "", headers['Set-Cookie']
assert_not_equal session_payload, cookies[SessionKey]

get '/get_session_value'
assert_response :success
assert_equal 'foo: nil', response.body
end
end

def test_setting_session_value_after_session_reset
with_test_route_set do
get '/set_session_value'
assert_response :success
session_payload = response.body
assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly",
headers['Set-Cookie']

get '/call_reset_session'
assert_response :success
assert_not_equal "", headers['Set-Cookie']
assert_not_equal session_payload, cookies[SessionKey]

get '/get_session_value'
assert_response :success
assert_equal 'foo: nil', response.body
end
end

def test_setting_session_value_after_session_reset def test_setting_session_value_after_session_reset
with_test_route_set do with_test_route_set do
get '/set_session_value' get '/set_session_value'
Expand Down

0 comments on commit d793a56

Please sign in to comment.