mirror of https://github.com/rails/rails
Merge pull request #49718 from fatkodima/fix-ordered_options-nested-dig
Fix `OrderedOptions#dig` for array indexes
This commit is contained in:
commit
10d880dcd2
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue