mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix reset_session with ActiveRecord store [#2200 state:resolved]
This commit is contained in:
parent
b33c0d9832
commit
01d7acd11d
2 changed files with 12 additions and 4 deletions
|
@ -28,9 +28,9 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
|
|||
end
|
||||
|
||||
def call_reset_session
|
||||
session[:bar]
|
||||
session[:foo]
|
||||
reset_session
|
||||
session[:bar] = "baz"
|
||||
session[:foo] = "baz"
|
||||
head :ok
|
||||
end
|
||||
|
||||
|
@ -91,7 +91,7 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
|
|||
|
||||
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
|
||||
|
|
|
@ -295,7 +295,7 @@ module ActiveRecord
|
|||
|
||||
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
|
||||
|
||||
|
@ -309,6 +309,14 @@ module ActiveRecord
|
|||
|
||||
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) ||
|
||||
|
|
Loading…
Reference in a new issue