From 6375569484ce08f53dec8064146c2ca0c74affcd Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 19 May 2005 19:13:30 +0000 Subject: Fixed that HashWithIndifferentAccess stringified all keys including symbols, ints, objects, and arrays #1162 [Nicholas Seckar] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1329 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/CHANGELOG | 2 ++ .../lib/active_support/core_ext/hash/indifferent_access.rb | 2 +- activesupport/test/core_ext/hash_ext_test.rb | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index cc0bdf6586..1cdc0b08c6 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that HashWithIndifferentAccess stringified all keys including symbols, ints, objects, and arrays #1162 [Nicholas Seckar] + * Fixed Time#last_year to go back in time, not forward #1278 [fabien@odilat.com] * Fixed the pluralization of analysis to analyses #1295 [seattle@rootimage.msu.edu] 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 00cb0b0b51..91445610e2 100644 --- a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +++ b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb @@ -3,7 +3,7 @@ class HashWithIndifferentAccess < Hash def initialize(constructor = {}) if constructor.is_a?(Hash) super() - update(constructor.stringify_keys) + update(constructor) else super(constructor) end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 152ce83555..8addd895cc 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -110,4 +110,10 @@ class HashExtTest < Test::Unit::TestCase 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"}} end + + def test_assorted_keys_not_stringified + original = {Object.new => 2, 1 => 2, [] => true} + indiff = original.with_indifferent_access + assert(!indiff.keys.any? {|k| k.kind_of? String}, "A key was converted to a string!") + end end -- cgit v1.2.3