Skip to content

Commit d424cab

Browse files
authored
Merge pull request rails#50061 from andrewn617/database-configs-for-with-symbol
DatabaseConfigurations#configs_for can accept a symbol in the name param
2 parents 67bc765 + c7063f9 commit d424cab

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* `DatabaseConfigurations#configs_for` can accept a symbol in the `name` parameter.
2+
3+
*Andrew Novoselac*
4+
15
* Fix `where(field: values)` queries when `field` is a serialized attribute
26
(for example, when `field` uses `ActiveRecord::Base.serialize` or is a JSON
37
column).

activerecord/lib/active_record/database_configurations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def configs_for(env_name: nil, name: nil, config_key: nil, include_hidden: false
113113

114114
if name
115115
configs.find do |db_config|
116-
db_config.name == name
116+
db_config.name == name.to_s
117117
end
118118
else
119119
configs

activerecord/test/cases/database_configurations_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ def test_configs_for_getter_with_name
3535
ENV["RAILS_ENV"] = previous_env
3636
end
3737

38+
def test_configs_for_with_name_symbol
39+
previous_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "arunit2"
40+
41+
config = ActiveRecord::Base.configurations.configs_for(name: :primary)
42+
43+
assert_equal "arunit2", config.env_name
44+
assert_equal "primary", config.name
45+
ensure
46+
ENV["RAILS_ENV"] = previous_env
47+
end
48+
3849
def test_configs_for_getter_with_env_and_name
3950
config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
4051

0 commit comments

Comments
 (0)