提交 63c4e976 编写于 作者: G Gannon McGibbon

Stringify database configurations

上级 06274428
* 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.
......
......@@ -104,7 +104,7 @@ def build_configs(configs)
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 @@ def walk_configs(env_name, spec_name, config)
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
......
......@@ -151,6 +151,30 @@ def test_establish_connection_using_top_level_key_in_two_level_config
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册