Skip to content

Commit c87e16b

Browse files
committed
Credentials: support hash style access in more cases
Fixes rails#42351 rails#42106 broke if you wanted to treat a set of nested credentials as a hash. This PR fixes it.
1 parent 10d74db commit c87e16b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

activesupport/lib/active_support/encrypted_configuration.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ def config
3535

3636
private
3737
def deep_transform(hash)
38-
hash.transform_values { |value| value.is_a?(Hash) ? ActiveSupport::InheritableOptions.new(deep_transform(value)) : value }
38+
return hash unless hash.is_a?(Hash)
39+
40+
h = ActiveSupport::InheritableOptions.new
41+
hash.each do |k, v|
42+
h[k] = deep_transform(v)
43+
end
44+
h
3945
end
4046

4147
def options

activesupport/test/encrypted_configuration_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class EncryptedConfigurationTest < ActiveSupport::TestCase
4545
assert_not @credentials.something.bad
4646
assert_equal "bar", @credentials.dig(:something, :nested, :foo)
4747
assert_equal "bar", @credentials.something.nested.foo
48+
assert_equal [:good, :bad, :nested], @credentials.something.keys
49+
assert_equal ({ good: true, bad: false, nested: { foo: "bar" } }), @credentials.something
4850
end
4951

5052
test "reading comment-only configuration" do

0 commit comments

Comments
 (0)