Skip to content

Commit

Permalink
Make #to_options an alias for #symbolize_keys
Browse files Browse the repository at this point in the history
Fixes #34359

Prior to 5.2.0 (2cad8d7), HashWithIndifferentAccess#to_options acted as
an alias to HashWithIndifferentAccess#symbolize_keys. Now, #to_options
returns an instance of HashWithIndifferentAccess while #symbolize_keys
returns and instance of Hash.

This pr makes it so HashWithIndifferentAccess#to_options acts as an
alias for HashWithIndifferentAccess#symbolize_keys once again.
  • Loading branch information
weilandia committed Nov 1, 2018
1 parent f98901c commit 4ba5386
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 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*
Expand Down
Expand Up @@ -289,6 +289,7 @@ def deep_stringify_keys; dup end
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

Expand Down
7 changes: 7 additions & 0 deletions activesupport/test/hash_with_indifferent_access_test.rb
Expand Up @@ -57,6 +57,13 @@ def test_symbolize_keys_for_hash_with_indifferent_access
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
Expand Down

0 comments on commit 4ba5386

Please sign in to comment.