aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/hash
diff options
context:
space:
mode:
authorEmily <emily@mongodb.com>2016-04-12 10:49:07 +0200
committerEmily <emily@mongodb.com>2016-04-12 10:49:07 +0200
commit64ae9a58ae54d7d036e930e75fac3e4a1ab0052e (patch)
treee18db7ef7bc2844da0d5fdebe64279953cb40bd4 /activesupport/test/core_ext/hash
parentdb9bc8097399aab9c866175b12e9e099b6c83ffa (diff)
downloadrails-64ae9a58ae54d7d036e930e75fac3e4a1ab0052e.tar.gz
rails-64ae9a58ae54d7d036e930e75fac3e4a1ab0052e.tar.bz2
rails-64ae9a58ae54d7d036e930e75fac3e4a1ab0052e.zip
Restore Hash#transform_keys behavior to always return a Hash instance
Diffstat (limited to 'activesupport/test/core_ext/hash')
-rw-r--r--activesupport/test/core_ext/hash/transform_keys_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash/transform_keys_test.rb b/activesupport/test/core_ext/hash/transform_keys_test.rb
index 99af274614..962d3a30b6 100644
--- a/activesupport/test/core_ext/hash/transform_keys_test.rb
+++ b/activesupport/test/core_ext/hash/transform_keys_test.rb
@@ -43,4 +43,20 @@ class TransformKeysTest < ActiveSupport::TestCase
original.transform_keys!.with_index { |k, i| [k, i].join.to_sym }
assert_equal({ a0: 'a', b1: 'b' }, original)
end
+
+ test "transform_keys returns a Hash instance when self is inherited from Hash" do
+ class HashDescendant < ::Hash
+ def initialize(elements = nil)
+ super(elements)
+ (elements || {}).each_pair{ |key, value| self[key] = value }
+ end
+ end
+
+ original = HashDescendant.new({ a: 'a', b: 'b' })
+ mapped = original.transform_keys { |k| "#{k}!".to_sym }
+
+ assert_equal({ a: 'a', b: 'b' }, original)
+ assert_equal({ a!: 'a', b!: 'b' }, mapped)
+ assert_equal(::Hash, mapped.class)
+ end
end