Permalink
Browse files

Fix SqlBypass.data_column= problem. SqlBypass.find_by_session_id meth…

…od didn't use this assignment.
  • Loading branch information...
1 parent 088022e commit cd44862d7269c5ffe75a4947482918a7d4f1bb2e @kennyj committed Jul 14, 2012
View
2 activerecord/lib/active_record/session_store.rb
@@ -218,7 +218,7 @@ def connection_pool
# 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.to_s)}")
+ if record = connection.select_one("SELECT #{connection.quote_column_name(data_column)} AS data FROM #{@@table_name} WHERE #{connection.quote_column_name(@@session_id_column)}=#{connection.quote(session_id.to_s)}")
new(:session_id => session_id, :marshaled_data => record['data'])
end
end
View
14 activerecord/test/cases/session_store/sql_bypass_test.rb
@@ -56,6 +56,20 @@ def test_destroy
s.destroy
assert_nil SqlBypass.find_by_session_id session_id
end
+
+ def test_data_column
+ SqlBypass.drop_table! if exists = Session.table_exists?
+ old, SqlBypass.data_column = SqlBypass.data_column, 'foo'
+ SqlBypass.create_table!
+
+ session_id = 20
+ SqlBypass.new(:data => 'hello', :session_id => session_id).save
+ assert_equal 'hello', SqlBypass.find_by_session_id(session_id).data
+ ensure
+ SqlBypass.drop_table!
+ SqlBypass.data_column = old
+ SqlBypass.create_table! if exists
+ end
end
end
end

0 comments on commit cd44862

Please sign in to comment.