aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-30 18:01:56 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-09-30 18:02:55 +0900
commitd39879435c51af1b9966f9037a9962146ff1ea71 (patch)
tree02779b136dd4c61033c4c6bccf6e0d61257c39af /activesupport
parentdabc57050fe30e9589823ffb606323a50ee9f6d4 (diff)
downloadrails-d39879435c51af1b9966f9037a9962146ff1ea71.tar.gz
rails-d39879435c51af1b9966f9037a9962146ff1ea71.tar.bz2
rails-d39879435c51af1b9966f9037a9962146ff1ea71.zip
Testing to ensure both bang and non-bang methods behaves consistently
Follow up of #30728.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/test/hash_with_indifferent_access_test.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activesupport/test/hash_with_indifferent_access_test.rb b/activesupport/test/hash_with_indifferent_access_test.rb
index b878ac20fa..41d653fa59 100644
--- a/activesupport/test/hash_with_indifferent_access_test.rb
+++ b/activesupport/test/hash_with_indifferent_access_test.rb
@@ -406,6 +406,29 @@ class HashWithIndifferentAccessTest < ActiveSupport::TestCase
assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
end
+ def test_indifferent_transform_keys_bang
+ indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings)
+ indifferent_strings.transform_keys! { |k| k * 2 }
+
+ assert_equal({ "aa" => 1, "bb" => 2 }, indifferent_strings)
+ assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
+ end
+
+ def test_indifferent_transform_values
+ hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).transform_values { |v| v * 2 }
+
+ assert_equal({ "a" => 2, "b" => 4 }, hash)
+ assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
+ end
+
+ def test_indifferent_transform_values_bang
+ indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings)
+ indifferent_strings.transform_values! { |v| v * 2 }
+
+ assert_equal({ "a" => 2, "b" => 4 }, indifferent_strings)
+ assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
+ end
+
def test_indifferent_compact
hash_contain_nil_value = @strings.merge("z" => nil)
hash = ActiveSupport::HashWithIndifferentAccess.new(hash_contain_nil_value)