Skip to content

Commit

Permalink
Fix reset_session with ActiveRecord store [#2200 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed May 17, 2009
1 parent b33c0d9 commit 01d7acd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions actionpack/test/activerecord/active_record_store_test.rb
Expand Up @@ -28,9 +28,9 @@ def get_session_id
end

def call_reset_session
session[:bar]
session[:foo]
reset_session
session[:bar] = "baz"
session[:foo] = "baz"
head :ok
end

Expand Down Expand Up @@ -91,7 +91,7 @@ def test_setting_session_value_after_session_reset

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

get '/get_session_id'
assert_response :success
Expand Down
10 changes: 9 additions & 1 deletion activerecord/lib/active_record/session_store.rb
Expand Up @@ -295,7 +295,7 @@ def get_session(env, sid)

def set_session(env, sid, session_data)
Base.silence do
record = env[SESSION_RECORD_KEY] ||= find_session(sid)
record = get_session_model(env, sid)
record.data = session_data
return false unless record.save

Expand All @@ -309,6 +309,14 @@ def set_session(env, sid, session_data)

return true
end

def get_session_model(env, sid)
if env[ENV_SESSION_OPTIONS_KEY][:id].nil?
env[SESSION_RECORD_KEY] = find_session(sid)
else
env[SESSION_RECORD_KEY] ||= find_session(sid)
end
end

def find_session(id)
@@session_class.find_by_session_id(id) ||
Expand Down

0 comments on commit 01d7acd

Please sign in to comment.