diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-11-01 13:21:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-01 13:21:09 -0400 |
commit | d80925b169f0db950697868f5659a67cc03e8654 (patch) | |
tree | e7bbfbb1db57b4aff6e44f86d90aeb09ef309b8c | |
parent | 7ac05a804d1f204ced084ed141e5aa00e4caeb3e (diff) | |
parent | 4ba5386e6c647b285490b0a9f44fcf617daeda41 (diff) | |
download | rails-d80925b169f0db950697868f5659a67cc03e8654.tar.gz rails-d80925b169f0db950697868f5659a67cc03e8654.tar.bz2 rails-d80925b169f0db950697868f5659a67cc03e8654.zip |
Merge pull request #34360 from weilandia/34359_hash_with_indifferent_access_to_options
Make ActiveSupport HashWithIndifferentAccess#to_options and alias for HashWithIndifferentAccess#symbolize_keys
-rw-r--r-- | activesupport/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 1 | ||||
-rw-r--r-- | activesupport/test/hash_with_indifferent_access_test.rb | 7 |
3 files changed, 13 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 92f5f64719..98d232da33 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* Fix bug where `#to_options` for `ActiveSupport::HashWithIndifferentAccess` + would not act as alias for `#symbolize_keys`. + + *Nick Weiland* + * Improve the logic that detects non-autoloaded constants. *Jan Habermann*, *Xavier Noria* diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 2fac579469..f1af76019a 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -289,6 +289,7 @@ module ActiveSupport undef :symbolize_keys! undef :deep_symbolize_keys! def symbolize_keys; to_hash.symbolize_keys! end + alias_method :to_options, :symbolize_keys def deep_symbolize_keys; to_hash.deep_symbolize_keys! end def to_options!; self end diff --git a/activesupport/test/hash_with_indifferent_access_test.rb b/activesupport/test/hash_with_indifferent_access_test.rb index af67ed21c8..f81e0dc70f 100644 --- a/activesupport/test/hash_with_indifferent_access_test.rb +++ b/activesupport/test/hash_with_indifferent_access_test.rb @@ -57,6 +57,13 @@ class HashWithIndifferentAccessTest < ActiveSupport::TestCase assert_equal @symbols, @mixed.with_indifferent_access.symbolize_keys end + def test_to_options_for_hash_with_indifferent_access + assert_instance_of Hash, @symbols.with_indifferent_access.to_options + assert_equal @symbols, @symbols.with_indifferent_access.to_options + assert_equal @symbols, @strings.with_indifferent_access.to_options + assert_equal @symbols, @mixed.with_indifferent_access.to_options + end + def test_deep_symbolize_keys_for_hash_with_indifferent_access assert_instance_of Hash, @nested_symbols.with_indifferent_access.deep_symbolize_keys assert_equal @nested_symbols, @nested_symbols.with_indifferent_access.deep_symbolize_keys |