From 4dcd4069f577e2105ea25929be1350fcefb9f71d Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sat, 8 Dec 2007 00:12:52 +0000 Subject: Fix HashWithIndifferentAccess#to_options! so it doesn't clear the options hash. Closes #10419 [ReinH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8332 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/CHANGELOG | 2 ++ .../lib/active_support/core_ext/hash/indifferent_access.rb | 1 + activesupport/test/core_ext/hash_ext_test.rb | 8 ++++++++ 3 files changed, 11 insertions(+) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 40fdbbbf45..67da6f2379 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,3 +1,5 @@ +* Fix HashWithIndifferentAccess#to_options! so it doesn't clear the options hash. Closes #10419 [ReinH] + *2.0.1* (December 7th, 2007) * Added Array#from and Array#to that behaves just from String#from and String#to [DHH] diff --git a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb index 01d5b3a6a3..fda0489e76 100644 --- a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +++ b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb @@ -63,6 +63,7 @@ class HashWithIndifferentAccess < Hash def stringify_keys!; self end def symbolize_keys!; self end + def to_options!; self end # Convert to a Hash with String keys. def to_hash diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 2be9ab8999..3763f47c68 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -205,6 +205,14 @@ class HashExtTest < Test::Unit::TestCase assert_equal 1, h[:first] end + def test_to_options_on_indifferent_preserves_hash + h = HashWithIndifferentAccess.new + h['first'] = 1 + h.to_options! + assert_equal 1, h['first'] + end + + def test_indifferent_subhashes h = {'user' => {'id' => 5}}.with_indifferent_access ['user', :user].each {|user| [:id, 'id'].each {|id| assert_equal 5, h[user][id], "h[#{user.inspect}][#{id.inspect}] should be 5"}} -- cgit v1.2.3