aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2016-05-25 00:14:39 -0400
committerArthur Neves <arthurnn@gmail.com>2016-05-25 00:14:39 -0400
commit028748945b7a3bb15555b90a58905190c601a15b (patch)
treec8c355803251a7eefe9bd6fa751e5881f99e68df /activerecord
parent779ccf8a0e6a8bf7bb362c30dac4a340599ab113 (diff)
downloadrails-028748945b7a3bb15555b90a58905190c601a15b.tar.gz
rails-028748945b7a3bb15555b90a58905190c601a15b.tar.bz2
rails-028748945b7a3bb15555b90a58905190c601a15b.zip
Add to_hash to specification
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb3
-rw-r--r--activerecord/lib/active_record/connection_adapters/connection_specification.rb4
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb2
-rw-r--r--activerecord/test/cases/connection_adapters/connection_handler_test.rb2
4 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index ca04058539..c341773be1 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -911,8 +911,7 @@ module ActiveRecord
# A connection was established in an ancestor process that must have
# subsequently forked. We can't reuse the connection, but we can copy
# the specification and establish a new connection with it.
- spec = ancestor_pool.spec
- establish_connection(spec.config.merge("name" => spec.name)).tap do |pool|
+ establish_connection(ancestor_pool.spec.to_hash).tap do |pool|
pool.schema_cache = ancestor_pool.schema_cache if ancestor_pool.schema_cache
end
else
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb
index 0f4bd1c84a..346916337e 100644
--- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb
+++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb
@@ -13,6 +13,10 @@ module ActiveRecord
@config = original.config.dup
end
+ def to_hash
+ @config.merge(name: @name)
+ end
+
# Expands a connection string into a hash.
class ConnectionUrlResolver # :nodoc:
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index cc8b2afa42..e3e665e149 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -120,7 +120,7 @@ module ActiveRecord
old_pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool(ActiveRecord::Base.connection_specification_name)
each_local_configuration { |configuration| create configuration }
if old_pool
- ActiveRecord::Base.connection_handler.establish_connection(old_pool.spec.config.merge("name" => old_pool.spec.name))
+ ActiveRecord::Base.connection_handler.establish_connection(old_pool.spec.to_hash)
end
end
diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
index 039aca73c6..a019cc6490 100644
--- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb
+++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
@@ -13,7 +13,7 @@ module ActiveRecord
config = {"readonly" => {"adapter" => 'sqlite3'}}
resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new(config)
spec = resolver.spec(:readonly)
- @handler.establish_connection(spec.config.merge("name" => spec.name))
+ @handler.establish_connection(spec.to_hash)
assert_not_nil @handler.retrieve_connection_pool('readonly')
ensure