diff options
author | Michael Herold <opensource@michaeljherold.com> | 2019-12-13 12:06:06 -0600 |
---|---|---|
committer | Michael Herold <opensource@michaeljherold.com> | 2019-12-13 12:57:40 -0600 |
commit | 0d085afd391193a63c005b8f0fef5ed4be79910c (patch) | |
tree | 081b59b732b150e926b28e166ed26d124702bdfe /spec | |
parent | 9c6b5c860aa77bdfaaf416c5c098536b7e2eed5c (diff) | |
download | hashie-0d085afd391193a63c005b8f0fef5ed4be79910c.tar.gz |
Ensure that Hashie::Arrays are not deconverted
In order for `#dig` to work properly, we need Arrays to be
`Hashie::Array`s to be aware of the key conversion. Our original
`Mash#convert_value` method was deconverting `Hashie::Array`s into
normal Arrays and causing `#dig` to behave in an unexpected manner.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/hashie/mash_spec.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb index fa4e47b..4629124 100644 --- a/spec/hashie/mash_spec.rb +++ b/spec/hashie/mash_spec.rb @@ -982,6 +982,7 @@ describe Hashie::Mash do with_minimum_ruby('2.3.0') do describe '#dig' do subject { described_class.new(a: { b: 1 }) } + it 'accepts both string and symbol as key' do expect(subject.dig(:a, :b)).to eq(1) expect(subject.dig('a', 'b')).to eq(1) @@ -994,6 +995,14 @@ describe Hashie::Mash do expect(subject.dig('1', :b)).to eq(1) end end + + context 'when the Mash wraps a Hashie::Array' do + it 'handles digging into an array' do + mash = described_class.new(alphabet: { first_three: Hashie::Array['a', 'b', 'c'] }) + + expect(mash.dig(:alphabet, :first_three, 0)).to eq 'a' + end + end end end |