From de9e3238a008f8f20c5beedefb8787b6e51359d0 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 27 Sep 2017 13:18:34 +0900 Subject: Ensure `HashWithIndifferentAccess#transform_keys` to return `HashWithIndifferentAccess` Currently, `#transform_values`, `#select` and `#reject` return instance of `HashWithIndifferentAccess`. But `#transform_keys` returns instance of Hash. This behavior is a bit confusing. I think that `HashWithIndifferentAccess#transform_keys` should also return instance of `HashWithIndifferentAccess` as well as other methods. --- activesupport/test/hash_with_indifferent_access_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/hash_with_indifferent_access_test.rb b/activesupport/test/hash_with_indifferent_access_test.rb index b3788ee65c..b878ac20fa 100644 --- a/activesupport/test/hash_with_indifferent_access_test.rb +++ b/activesupport/test/hash_with_indifferent_access_test.rb @@ -399,6 +399,13 @@ class HashWithIndifferentAccessTest < ActiveSupport::TestCase assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings end + def test_indifferent_transform_keys + hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).transform_keys { |k| k * 2 } + + assert_equal({ "aa" => 1, "bb" => 2 }, hash) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash + end + def test_indifferent_compact hash_contain_nil_value = @strings.merge("z" => nil) hash = ActiveSupport::HashWithIndifferentAccess.new(hash_contain_nil_value) -- cgit v1.2.3