Ensure SqlBypass use ActiveRecord::Base connection

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#https://rails.lighthouseapp.com/attachments/106066/0001-Ensure-SqlBypass-use-ActiveRecord-Base-connection.patch state:committed]
This commit is contained in:
Luca Guidi 2009-03-31 16:39:13 +02:00 committed by Michael Koziarski
parent 0e9efae474
commit 42cdc7571d
2 changed files with 26 additions and 15 deletions

@ -45,23 +45,27 @@ def teardown
ActiveRecord::SessionStore.session_class.drop_table!
end
def test_setting_and_getting_session_value
with_test_route_set do
get '/set_session_value'
assert_response :success
assert cookies['_session_id']
%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 '/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 '/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
get '/get_session_value'
assert_response :success
assert_equal 'foo: "baz"', response.body
end
end
end
end
@ -171,4 +175,11 @@ def with_test_route_set
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

@ -184,7 +184,7 @@ def connection
# Look up a session by id and unmarshal its data if found.
def find_by_session_id(session_id)
if record = @@connection.select_one("SELECT * FROM #{@@table_name} WHERE #{@@session_id_column}=#{@@connection.quote(session_id)}")
if record = connection.select_one("SELECT * FROM #{@@table_name} WHERE #{@@session_id_column}=#{connection.quote(session_id)}")
new(:session_id => session_id, :marshaled_data => record['data'])
end
end