Credentials: support hash style access in more cases

Fixes https://github.com/rails/rails/issues/42351

https://github.com/rails/rails/pull/42106 broke if you wanted to treat a set of nested credentials as a hash. This PR fixes it.
This commit is contained in:
Alex Ghiculescu 2021-06-02 10:34:22 -05:00
parent 10d74dbe86
commit c87e16bf0e
2 changed files with 9 additions and 1 deletions

View File

@ -35,7 +35,13 @@ module ActiveSupport
private
def deep_transform(hash)
hash.transform_values { |value| value.is_a?(Hash) ? ActiveSupport::InheritableOptions.new(deep_transform(value)) : value }
return hash unless hash.is_a?(Hash)
h = ActiveSupport::InheritableOptions.new
hash.each do |k, v|
h[k] = deep_transform(v)
end
h
end
def options

View File

@ -45,6 +45,8 @@ class EncryptedConfigurationTest < ActiveSupport::TestCase
assert_not @credentials.something.bad
assert_equal "bar", @credentials.dig(:something, :nested, :foo)
assert_equal "bar", @credentials.something.nested.foo
assert_equal [:good, :bad, :nested], @credentials.something.keys
assert_equal ({ good: true, bad: false, nested: { foo: "bar" } }), @credentials.something
end
test "reading comment-only configuration" do