Skip to content

Commit

Permalink
Ensure SqlBypass use ActiveRecord::Base connection
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#https://rails.lighthouseapp.com/attachments/106066/0001-Ensure-SqlBypass-use-ActiveRecord-Base-connection.patch state:committed]
  • Loading branch information
Luca Guidi authored and NZKoz committed Apr 5, 2009
1 parent 0e9efae commit 42cdc75
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
45 changes: 28 additions & 17 deletions actionpack/test/activerecord/active_record_store_test.rb
Expand Up @@ -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']

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
%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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/session_store.rb
Expand Up @@ -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
Expand Down

0 comments on commit 42cdc75

Please sign in to comment.