提交 279fef1f 编写于 作者: M Marcelo Silveira

Rename test file so that the test suite matches it, implement `persisted?` for...

Rename test file so that the test suite matches it, implement `persisted?` 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).
上级 7994496a
......@@ -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
......
......@@ -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!'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册