Permalink
Browse files

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]
  • Loading branch information...
Luca Guidi authored and NZKoz committed Mar 31, 2009
1 parent 0e9efae commit 42cdc7571d115c5eb4ece440001d221f24553100
@@ -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
@@ -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

0 comments on commit 42cdc75

Please sign in to comment.