mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix payload[:class_name]
to payload[:spec_name]
Follow up to #20818. `retrieve_connection` is passed `spec_name` instead of `klass` since #24844.
This commit is contained in:
parent
9a1ab66744
commit
38cd2aae43
5 changed files with 10 additions and 13 deletions
|
@ -855,7 +855,7 @@ module ActiveRecord
|
||||||
connection_id: object_id
|
connection_id: object_id
|
||||||
}
|
}
|
||||||
if spec
|
if spec
|
||||||
payload[:class_name] = spec.name
|
payload[:spec_name] = spec.name
|
||||||
payload[:config] = spec.config
|
payload[:config] = spec.config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -987,16 +987,11 @@ module ActiveRecord
|
||||||
|
|
||||||
# When connections are established in the future, begin a transaction too
|
# When connections are established in the future, begin a transaction too
|
||||||
@connection_subscriber = ActiveSupport::Notifications.subscribe('!connection.active_record') do |_, _, _, _, payload|
|
@connection_subscriber = ActiveSupport::Notifications.subscribe('!connection.active_record') do |_, _, _, _, payload|
|
||||||
model_class = nil
|
spec_name = payload[:spec_name] if payload.key?(:spec_name)
|
||||||
begin
|
|
||||||
model_class = payload[:class_name].constantize if payload[:class_name]
|
|
||||||
rescue NameError
|
|
||||||
model_class = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
if model_class
|
if spec_name
|
||||||
begin
|
begin
|
||||||
connection = ActiveRecord::Base.connection_handler.retrieve_connection(model_class)
|
connection = ActiveRecord::Base.connection_handler.retrieve_connection(spec_name)
|
||||||
rescue ConnectionNotEstablished
|
rescue ConnectionNotEstablished
|
||||||
connection = nil
|
connection = nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -347,8 +347,8 @@ module ActiveRecord
|
||||||
payloads << payload
|
payloads << payload
|
||||||
end
|
end
|
||||||
ActiveRecord::Base.establish_connection :arunit
|
ActiveRecord::Base.establish_connection :arunit
|
||||||
assert_equal [:class_name, :config, :connection_id], payloads[0].keys.sort
|
assert_equal [:config, :connection_id, :spec_name], payloads[0].keys.sort
|
||||||
assert_equal 'primary', payloads[0][:class_name]
|
assert_equal 'primary', payloads[0][:spec_name]
|
||||||
ensure
|
ensure
|
||||||
ActiveSupport::Notifications.unsubscribe(subscription) if subscription
|
ActiveSupport::Notifications.unsubscribe(subscription) if subscription
|
||||||
end
|
end
|
||||||
|
|
|
@ -650,10 +650,10 @@ class TransactionalFixturesOnConnectionNotification < ActiveRecord::TestCase
|
||||||
private
|
private
|
||||||
|
|
||||||
def fire_connection_notification(connection)
|
def fire_connection_notification(connection)
|
||||||
ActiveRecord::Base.connection_handler.stubs(:retrieve_connection).with(Book).returns(connection)
|
ActiveRecord::Base.connection_handler.stubs(:retrieve_connection).with('book').returns(connection)
|
||||||
message_bus = ActiveSupport::Notifications.instrumenter
|
message_bus = ActiveSupport::Notifications.instrumenter
|
||||||
payload = {
|
payload = {
|
||||||
class_name: 'Book',
|
spec_name: 'book',
|
||||||
config: nil,
|
config: nil,
|
||||||
connection_id: connection.object_id
|
connection_id: connection.object_id
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ require 'models/post'
|
||||||
require 'rack'
|
require 'rack'
|
||||||
|
|
||||||
class QueryCacheTest < ActiveRecord::TestCase
|
class QueryCacheTest < ActiveRecord::TestCase
|
||||||
|
self.use_transactional_tests = false
|
||||||
|
|
||||||
fixtures :tasks, :topics, :categories, :posts, :categories_posts
|
fixtures :tasks, :topics, :categories, :posts, :categories_posts
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
|
Loading…
Reference in a new issue