aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-09 18:30:05 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-09 18:30:05 -0300
commit3fe33a318f29c03966ca5892413884414421108c (patch)
tree326fb1e52316f1577b3fc65f19f8a4112c581135 /activesupport
parentdddbccb25a709e1897326e2a25d37da83bbfd717 (diff)
downloadrails-3fe33a318f29c03966ca5892413884414421108c.tar.gz
rails-3fe33a318f29c03966ca5892413884414421108c.tar.bz2
rails-3fe33a318f29c03966ca5892413884414421108c.zip
Fix bug that make HashWithIndifferentAccess work differently of Hash
Before HashWithIndifferentAccess were doing deep_dup of the inner hashes when Hash doesn't do. Now both are behaving in the same way.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb2
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb
index e782cfa2f5..e1eb81b8bc 100644
--- a/activesupport/lib/active_support/hash_with_indifferent_access.rb
+++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -57,7 +57,7 @@ module ActiveSupport
def initialize(constructor = {})
if constructor.respond_to?(:to_hash)
super()
- update(constructor.to_hash)
+ 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 cd0cb1a144..f18172a5ce 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -659,6 +659,14 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal 1, h['first']
end
+ def test_to_options_on_indifferent_preserves_works_as_hash_with_dup
+ h = HashWithIndifferentAccess.new({ a: { b: 'b' } })
+ dup = h.dup
+
+ dup[:a][:c] = 'c'
+ assert_equal 'c', h[:a][:c]
+ end
+
def test_indifferent_sub_hashes
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"}}