diff options
Diffstat (limited to 'actionpack/test/activerecord/active_record_store_test.rb')
-rw-r--r-- | actionpack/test/activerecord/active_record_store_test.rb | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb index 6a75e6050d..34f18806a2 100644 --- a/actionpack/test/activerecord/active_record_store_test.rb +++ b/actionpack/test/activerecord/active_record_store_test.rb @@ -21,6 +21,18 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest render :text => "foo: #{session[:foo].inspect}" end + def get_session_id + session[:foo] + render :text => "#{request.session_options[:id]}" + end + + def call_reset_session + session[:bar] + reset_session + session[:bar] = "baz" + head :ok + end + def rescue_action(e) raise end end @@ -33,31 +45,69 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest ActiveRecord::SessionStore.session_class.drop_table! end - def test_setting_and_getting_session_value + %w{ session sql_bypass }.each do |class_name| + define_method("test_setting_and_getting_session_value_with_#{class_name}_store") do + with_store class_name do + with_test_route_set do + get '/set_session_value' + assert_response :success + assert cookies['_session_id'] + + get '/get_session_value' + assert_response :success + assert_equal 'foo: "bar"', response.body + + get '/set_session_value', :foo => "baz" + assert_response :success + assert cookies['_session_id'] + + get '/get_session_value' + assert_response :success + assert_equal 'foo: "baz"', response.body + end + end + end + end + + def test_getting_nil_session_value + with_test_route_set do + 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 assert cookies['_session_id'] + session_id = cookies['_session_id'] - get '/get_session_value' + get '/call_reset_session' assert_response :success - assert_equal 'foo: "bar"', response.body + assert_not_equal [], headers['Set-Cookie'] - get '/set_session_value', :foo => "baz" + get '/get_session_value' assert_response :success - assert cookies['_session_id'] + assert_equal 'foo: nil', response.body - get '/get_session_value' + get '/get_session_id' assert_response :success - assert_equal 'foo: "baz"', response.body + assert_not_equal session_id, response.body end end - def test_getting_nil_session_value + def test_getting_session_id with_test_route_set do - get '/get_session_value' + get '/set_session_value' assert_response :success - assert_equal 'foo: nil', response.body + assert cookies['_session_id'] + session_id = cookies['_session_id'] + + get '/get_session_id' + assert_response :success + assert_equal session_id, response.body end end @@ -125,4 +175,11 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest yield end end + + def with_store(class_name) + session_class, ActiveRecord::SessionStore.session_class = + ActiveRecord::SessionStore.session_class, "ActiveRecord::SessionStore::#{class_name.camelize}".constantize + yield + ActiveRecord::SessionStore.session_class = session_class + end end |