diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2018-09-24 13:20:03 -0400 |
---|---|---|
committer | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2018-09-24 13:43:47 -0400 |
commit | 63c4e9765b53ae1f8b4674c45012295f873a40be (patch) | |
tree | 16844c8ead17b266a0b7608d082a714eccf75164 | |
parent | 06274428e534f8e12fc7d6904a89678b23c5b404 (diff) | |
download | rails-63c4e9765b53ae1f8b4674c45012295f873a40be.tar.gz rails-63c4e9765b53ae1f8b4674c45012295f873a40be.tar.bz2 rails-63c4e9765b53ae1f8b4674c45012295f873a40be.zip |
Stringify database configurations
-rw-r--r-- | activerecord/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/database_configurations.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/connection_adapters/connection_handler_test.rb | 24 |
3 files changed, 30 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index cfc5647969..0aec999aba 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash. + + *Gannon McGibbon* + * Don't update counter cache unless the record is actually saved. Fixes #31493, #33113, #33117. diff --git a/activerecord/lib/active_record/database_configurations.rb b/activerecord/lib/active_record/database_configurations.rb index 9ff63c6e10..fa1589511e 100644 --- a/activerecord/lib/active_record/database_configurations.rb +++ b/activerecord/lib/active_record/database_configurations.rb @@ -104,7 +104,7 @@ module ActiveRecord return configs.configurations if configs.is_a?(DatabaseConfigurations) build_db_config = configs.each_pair.flat_map do |env_name, config| - walk_configs(env_name, "primary", config) + walk_configs(env_name.to_s, "primary", config) end.compact if url = ENV["DATABASE_URL"] @@ -119,7 +119,7 @@ module ActiveRecord when String build_db_config_from_string(env_name, spec_name, config) when Hash - build_db_config_from_hash(env_name, spec_name, config) + build_db_config_from_hash(env_name, spec_name, config.stringify_keys) 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 8c204a2692..6e11b4bb87 100644 --- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb +++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb @@ -151,6 +151,30 @@ module ActiveRecord ActiveRecord::Base.configurations = @prev_configs end + def test_symbolized_configurations_assignment + @prev_configs = ActiveRecord::Base.configurations + config = { + development: { + primary: { + adapter: "sqlite3", + database: "db/development.sqlite3", + }, + }, + test: { + primary: { + adapter: "sqlite3", + database: "db/test.sqlite3", + }, + }, + } + ActiveRecord::Base.configurations = config + ActiveRecord::Base.configurations.configs_for.each do |config| + assert_instance_of ActiveRecord::DatabaseConfigurations::HashConfig, config + end + ensure + ActiveRecord::Base.configurations = @prev_configs + end + def test_retrieve_connection assert @handler.retrieve_connection(@spec_name) end |