Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't destroy a HashWithIndifferentAccess if symbolize_keys! or strin…

…gify_keys! is called on it. Closes #5076. [Marcel Molina Jr., guy.naor@famundo.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4339 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit f2b3deb85cab1389d6b895b2e45b33054a96a6ba 1 parent f9f6543
Marcel Molina authored
View
2  activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Don't destroy a HashWithIndifferentAccess if symbolize_keys! or stringify_keys! is called on it. Closes #5076. [Marcel Molina Jr., guy.naor@famundo.com]
+
* Document Module::delegate. #5002 [pergesu@gmail.com]
* Replace alias method chaining with Module#alias_method_chain. [Marcel Molina Jr.]
View
3  activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
@@ -56,6 +56,9 @@ def merge(hash)
def delete(key)
super(convert_key(key))
end
+
+ def stringify_keys!; self end
+ def symbolize_keys!; self end
protected
def convert_key(key)
View
11 activesupport/test/core_ext/hash_ext_test.rb
@@ -145,6 +145,17 @@ def test_indifferent_deleting
assert_equal hash.delete('a'), nil
end
+ def test_stringify_and_symbolize_keys_on_indifferent_preserves_hash
+ h = HashWithIndifferentAccess.new
+ h[:first] = 1
+ h.stringify_keys!
+ assert_equal 1, h['first']
+ h = HashWithIndifferentAccess.new
+ h['first'] = 1
+ h.symbolize_keys!
+ assert_equal 1, h[:first]
+ end
+
def test_assert_valid_keys
assert_nothing_raised do
{ :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])
Please sign in to comment.
Something went wrong with that request. Please try again.