diff options
author | Jon Moss <me@jonathanmoss.me> | 2016-02-01 21:16:07 -0500 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2016-02-01 21:49:13 -0500 |
commit | c918a3a0691d54f0702c26aac3f47e9449fd2a24 (patch) | |
tree | 4c7ef70de7c13e3d6dd0f5ce07fafc49d50534e7 /activesupport | |
parent | 538bce1f7c676f4a5b3d800ed0f68ec065776a7f (diff) | |
download | rails-c918a3a0691d54f0702c26aac3f47e9449fd2a24.tar.gz rails-c918a3a0691d54f0702c26aac3f47e9449fd2a24.tar.bz2 rails-c918a3a0691d54f0702c26aac3f47e9449fd2a24.zip |
Fix regression in `Hash#dig` for HashWithIndifferentAccess.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 3 | ||||
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 10 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 6 |
3 files changed, 16 insertions, 3 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index a35214bbe1..bd333da081 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,6 @@ +* Fix regression in `Hash#dig` for HashWithIndifferentAccess. + *Jon Moss* + ## Rails 5.0.0.beta2 (February 01, 2016) ## * Change number_to_currency behavior for checking negativity. diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index b878f31e75..03770a197c 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -69,9 +69,13 @@ module ActiveSupport end def default(*args) - key = args.first - args[0] = key.to_s if key.is_a?(Symbol) - super(*args) + arg_key = args.first + + if include?(key = convert_key(arg_key)) + self[key] + else + super + end end def self.new_from_hash_copying_default(hash) diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 1b66f784e4..be8583e704 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -702,6 +702,12 @@ class HashExtTest < ActiveSupport::TestCase assert_equal h.class, h.dup.class end + def test_nested_dig_indifferent_access + skip if RUBY_VERSION < "2.3.0" + data = {"this" => {"views" => 1234}}.with_indifferent_access + assert_equal 1234, data.dig(:this, :views) + end + def test_assert_valid_keys assert_nothing_raised do { :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) |