diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-11-13 13:54:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-13 13:54:47 -0500 |
commit | 7a954211e6ffe9b482fbd65711edadbb265bf1a7 (patch) | |
tree | c7b069db433fc08e33a7aa54e5f4c06b7992a19c /activerecord/test | |
parent | e1290a87b1c0f49d2a258d4be2600f78ca4767ad (diff) | |
parent | d6ba146f1890eb0e5c33e19241388c4f5f53f581 (diff) | |
download | rails-7a954211e6ffe9b482fbd65711edadbb265bf1a7.tar.gz rails-7a954211e6ffe9b482fbd65711edadbb265bf1a7.tar.bz2 rails-7a954211e6ffe9b482fbd65711edadbb265bf1a7.zip |
Merge pull request #34429 from bogdanvlviv/ensure-that-connected_to-establish_connection
Ensure that `ActiveRecord::Base#connected_to` with `:database` establishes connection
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb b/activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb index a520fb1303..0e4ea62113 100644 --- a/activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb +++ b/activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb @@ -127,6 +127,9 @@ module ActiveRecord ActiveRecord::Base.connected_to(database: { writing: "postgres://localhost/bar" }) do handler = ActiveRecord::Base.connection_handler assert_equal handler, ActiveRecord::Base.connection_handlers[:writing] + + assert_not_nil pool = handler.retrieve_connection_pool("primary") + assert_equal({ adapter: "postgresql", database: "bar", host: "localhost" }, pool.spec.config) end ensure ActiveRecord::Base.establish_connection(:arunit) @@ -136,11 +139,14 @@ module ActiveRecord def test_switching_connections_with_database_config_hash previous_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "default_env" - config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" } + config = { adapter: "sqlite3", database: "db/readonly.sqlite3" } ActiveRecord::Base.connected_to(database: { writing: config }) do handler = ActiveRecord::Base.connection_handler assert_equal handler, ActiveRecord::Base.connection_handlers[:writing] + + assert_not_nil pool = handler.retrieve_connection_pool("primary") + assert_equal(config, pool.spec.config) end ensure ActiveRecord::Base.establish_connection(:arunit) @@ -150,11 +156,23 @@ module ActiveRecord def test_switching_connections_with_database_symbol previous_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "default_env" - ActiveRecord::Base.connected_to(database: :arunit2) do + config = { + "default_env" => { + "readonly" => { adapter: "sqlite3", database: "db/readonly.sqlite3" }, + "primary" => { adapter: "sqlite3", database: "db/primary.sqlite3" } + } + } + @prev_configs, ActiveRecord::Base.configurations = ActiveRecord::Base.configurations, config + + ActiveRecord::Base.connected_to(database: :readonly) do handler = ActiveRecord::Base.connection_handler - assert_equal handler, ActiveRecord::Base.connection_handlers[:arunit2] + assert_equal handler, ActiveRecord::Base.connection_handlers[:readonly] + + assert_not_nil pool = handler.retrieve_connection_pool("primary") + assert_equal(config["default_env"]["readonly"], pool.spec.config) end ensure + ActiveRecord::Base.configurations = @prev_configs ActiveRecord::Base.establish_connection(:arunit) ENV["RAILS_ENV"] = previous_env end |