diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2018-10-30 08:56:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-30 08:56:34 -0400 |
commit | 6889e720ccd264ddcf47162742c347a4559a9129 (patch) | |
tree | b99ed3f879d2b27514b42ce18cf5d98697beb374 /activerecord/test | |
parent | f5ddf817841b85de3595788b348d626beac33a05 (diff) | |
parent | abf51844bb598ffdd2e6b8aa722b75b5897d9a3f (diff) | |
download | rails-6889e720ccd264ddcf47162742c347a4559a9129.tar.gz rails-6889e720ccd264ddcf47162742c347a4559a9129.tar.bz2 rails-6889e720ccd264ddcf47162742c347a4559a9129.zip |
Merge pull request #34196 from gmcgibbon/connection_switch_string_name
Add support for hash and url configs to be used in connected_to
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb | 39 |
1 files changed, 39 insertions, 0 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 d4e8cbee81..a520fb1303 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 @@ -120,6 +120,45 @@ module ActiveRecord ENV["RAILS_ENV"] = previous_env end + def test_switching_connections_with_database_url + previous_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "default_env" + previous_url, ENV["DATABASE_URL"] = ENV["DATABASE_URL"], "postgres://localhost/foo" + + ActiveRecord::Base.connected_to(database: { writing: "postgres://localhost/bar" }) do + handler = ActiveRecord::Base.connection_handler + assert_equal handler, ActiveRecord::Base.connection_handlers[:writing] + end + ensure + ActiveRecord::Base.establish_connection(:arunit) + ENV["RAILS_ENV"] = previous_env + ENV["DATABASE_URL"] = previous_url + end + + 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" } + + ActiveRecord::Base.connected_to(database: { writing: config }) do + handler = ActiveRecord::Base.connection_handler + assert_equal handler, ActiveRecord::Base.connection_handlers[:writing] + end + ensure + ActiveRecord::Base.establish_connection(:arunit) + ENV["RAILS_ENV"] = previous_env + end + + def test_switching_connections_with_database_symbol + previous_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "default_env" + + ActiveRecord::Base.connected_to(database: :arunit2) do + handler = ActiveRecord::Base.connection_handler + assert_equal handler, ActiveRecord::Base.connection_handlers[:arunit2] + end + ensure + ActiveRecord::Base.establish_connection(:arunit) + ENV["RAILS_ENV"] = previous_env + end + def test_connects_to_with_single_configuration config = { "development" => { "adapter" => "sqlite3", "database" => "db/primary.sqlite3" }, |