mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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:
parent
10d74dbe86
commit
c87e16bf0e
2 changed files with 9 additions and 1 deletions
|
@ -35,7 +35,13 @@ module ActiveSupport
|
||||||
|
|
||||||
private
|
private
|
||||||
def deep_transform(hash)
|
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
|
end
|
||||||
|
|
||||||
def options
|
def options
|
||||||
|
|
|
@ -45,6 +45,8 @@ class EncryptedConfigurationTest < ActiveSupport::TestCase
|
||||||
assert_not @credentials.something.bad
|
assert_not @credentials.something.bad
|
||||||
assert_equal "bar", @credentials.dig(:something, :nested, :foo)
|
assert_equal "bar", @credentials.dig(:something, :nested, :foo)
|
||||||
assert_equal "bar", @credentials.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
|
end
|
||||||
|
|
||||||
test "reading comment-only configuration" do
|
test "reading comment-only configuration" do
|
||||||
|
|
Loading…
Reference in a new issue