diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-04-15 09:25:02 -0600 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-04-15 09:25:02 -0600 |
commit | b0d7ac0ff7462ce1b744411d244cee9074767c0f (patch) | |
tree | e97d2f3c543b5f6dde6ff8c80b34fbb9e60c6334 /activesupport/test | |
parent | 94a1edbc023fd82bf96705d86abc85d2eab14ba3 (diff) | |
parent | 64ae9a58ae54d7d036e930e75fac3e4a1ab0052e (diff) | |
download | rails-b0d7ac0ff7462ce1b744411d244cee9074767c0f.tar.gz rails-b0d7ac0ff7462ce1b744411d244cee9074767c0f.tar.bz2 rails-b0d7ac0ff7462ce1b744411d244cee9074767c0f.zip |
Merge pull request #24517 from estolfo/transform-keys-return-type-master
Restore Hash#transform_keys behavior to always return a Hash instance
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/hash/transform_keys_test.rb | 16 |
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 |