mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #6136 from mhfs/sqlbypass_fixes
Bring SqlByPassTest to light and fix broken tests
This commit is contained in:
commit
2a67a8cc59
2 changed files with 15 additions and 5 deletions
|
@ -218,7 +218,7 @@ module ActiveRecord
|
||||||
|
|
||||||
# Look up a session by id and unmarshal its data if found.
|
# Look up a session by id and unmarshal its data if found.
|
||||||
def find_by_session_id(session_id)
|
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'])
|
new(:session_id => session_id, :marshaled_data => record['data'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -241,6 +241,11 @@ module ActiveRecord
|
||||||
@new_record = @marshaled_data.nil?
|
@new_record = @marshaled_data.nil?
|
||||||
end
|
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.
|
# Lazy-unmarshal session state.
|
||||||
def data
|
def data
|
||||||
unless @data
|
unless @data
|
||||||
|
@ -287,7 +292,7 @@ module ActiveRecord
|
||||||
connect = connection
|
connect = connection
|
||||||
connect.delete <<-end_sql, 'Destroy session'
|
connect.delete <<-end_sql, 'Destroy session'
|
||||||
DELETE FROM #{table_name}
|
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_sql
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,11 @@ module ActiveRecord
|
||||||
assert !Session.table_exists?
|
assert !Session.table_exists?
|
||||||
end
|
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?
|
def test_persisted?
|
||||||
s = SqlBypass.new :data => 'foo', :session_id => 10
|
s = SqlBypass.new :data => 'foo', :session_id => 10
|
||||||
assert !s.persisted?, 'this is a new record!'
|
assert !s.persisted?, 'this is a new record!'
|
Loading…
Reference in a new issue