mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #29623 from kamipo/should_use_same_connection_in_query_cache
Should use the same connection in using query cache
This commit is contained in:
commit
9c2ad53bef
3 changed files with 5 additions and 11 deletions
|
@ -108,6 +108,7 @@ module ActiveRecord
|
|||
"sql.active_record",
|
||||
sql: sql,
|
||||
binds: binds,
|
||||
type_casted_binds: -> { type_casted_binds(binds) },
|
||||
name: name,
|
||||
connection_id: object_id,
|
||||
cached: true,
|
||||
|
|
|
@ -29,7 +29,7 @@ module ActiveRecord
|
|||
binds = nil
|
||||
|
||||
unless (payload[:binds] || []).empty?
|
||||
casted_params = type_casted_binds(payload[:binds], payload[:type_casted_binds])
|
||||
casted_params = type_casted_binds(payload[:type_casted_binds])
|
||||
binds = " " + payload[:binds].zip(casted_params).map { |attr, value|
|
||||
render_bind(attr, value)
|
||||
}.inspect
|
||||
|
@ -42,9 +42,8 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
private
|
||||
|
||||
def type_casted_binds(binds, casted_binds)
|
||||
casted_binds || ActiveRecord::Base.connection.type_casted_binds(binds)
|
||||
def type_casted_binds(casted_binds)
|
||||
casted_binds.respond_to?(:call) ? casted_binds.call : casted_binds
|
||||
end
|
||||
|
||||
def render_bind(attr, value)
|
||||
|
|
|
@ -323,6 +323,7 @@ class QueryCacheTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_cache_is_available_when_using_a_not_connected_connection
|
||||
skip "In-Memory DB can't test for using a not connected connection" if in_memory_db?
|
||||
with_temporary_connection_pool do
|
||||
spec_name = Task.connection_specification_name
|
||||
conf = ActiveRecord::Base.configurations["arunit"].merge("name" => "test2")
|
||||
|
@ -332,13 +333,6 @@ class QueryCacheTest < ActiveRecord::TestCase
|
|||
|
||||
Task.cache do
|
||||
begin
|
||||
if in_memory_db?
|
||||
Task.connection.create_table :tasks do |t|
|
||||
t.datetime :starting
|
||||
t.datetime :ending
|
||||
end
|
||||
ActiveRecord::FixtureSet.create_fixtures(self.class.fixture_path, ["tasks"], {}, ActiveRecord::Base)
|
||||
end
|
||||
assert_queries(1) { Task.find(1); Task.find(1) }
|
||||
ensure
|
||||
ActiveRecord::Base.connection_handler.remove_connection(Task.connection_specification_name)
|
||||
|
|
Loading…
Reference in a new issue