1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Stringify database configurations

This commit is contained in:
Gannon McGibbon 2018-09-24 13:20:03 -04:00
parent 06274428e5
commit 63c4e9765b
3 changed files with 30 additions and 2 deletions

View file

@ -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.

View file

@ -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

View file

@ -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