Merge pull request #49718 from fatkodima/fix-ordered_options-nested-dig

Fix `OrderedOptions#dig` for array indexes
This commit is contained in:
Ryuta Kamizono 2023-10-20 19:57:22 +09:00 committed by GitHub
commit 10d880dcd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -42,8 +42,8 @@ module ActiveSupport
super(key.to_sym)
end
def dig(*keys)
super(*keys.flatten.map(&:to_sym))
def dig(key, *identifiers)
super(key.to_sym, *identifiers)
end
def method_missing(name, *args)

View File

@ -46,6 +46,14 @@ class OrderedOptionsTest < ActiveSupport::TestCase
assert_equal 56, a.dig("test_key")
end
def test_nested_dig
a = ActiveSupport::OrderedOptions.new
a[:test_key] = [{ a: 1 }]
assert_equal 1, a.dig(:test_key, 0, :a)
assert_nil a.dig(:test_key, 1, :a)
end
def test_method_access
a = ActiveSupport::OrderedOptions.new