Skip to content
Browse files

Rename test file so that the test suite matches it, implement `persis…

…ted?` for SqlBypass as expected by tests and convert session_id to string before using on queries to get correct quotes on postgresql (avoid casting error).
  • Loading branch information...
1 parent 7994496 commit 279fef1f9fedf73d94fc09e34566b1c56ec04a4c @mhfs mhfs committed
View
15 activerecord/lib/active_record/session_store.rb
@@ -201,10 +201,10 @@ class SqlBypass
class << self
alias :data_column_name :data_column
-
+
# Use the ActiveRecord::Base.connection by default.
attr_writer :connection
-
+
# Use the ActiveRecord::Base.connection_pool by default.
attr_writer :connection_pool
@@ -218,12 +218,12 @@ 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)}")
+ if record = connection.select_one("SELECT * FROM #{@@table_name} WHERE #{@@session_id_column}=#{connection.quote(session_id.to_s)}")
new(:session_id => session_id, :marshaled_data => record['data'])
end
end
end
-
+
delegate :connection, :connection=, :connection_pool, :connection_pool=, :to => self
attr_reader :session_id, :new_record
@@ -241,6 +241,11 @@ def initialize(attributes)
@new_record = @marshaled_data.nil?
end
+ # Returns true if the record is persisted, i.e. it's not a new record
+ def persisted?
+ !@new_record
+ end
+
# Lazy-unmarshal session state.
def data
unless @data
@@ -287,7 +292,7 @@ def destroy
connect = connection
connect.delete <<-end_sql, 'Destroy session'
DELETE FROM #{table_name}
- WHERE #{connect.quote_column_name(session_id_column)}=#{connect.quote(session_id)}
+ WHERE #{connect.quote_column_name(session_id_column)}=#{connect.quote(session_id.to_s)}
end_sql
end
end
View
5 ...rd/test/cases/session_store/sql_bypass.rb → ...st/cases/session_store/sql_bypass_test.rb
@@ -18,6 +18,11 @@ def test_create_table
assert !Session.table_exists?
end
+ def test_new_record?
+ s = SqlBypass.new :data => 'foo', :session_id => 10
+ assert s.new_record?, 'this is a new record!'
+ end
+
def test_persisted?
s = SqlBypass.new :data => 'foo', :session_id => 10
assert !s.persisted?, 'this is a new record!'

0 comments on commit 279fef1

Please sign in to comment.
Something went wrong with that request. Please try again.