diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-05-23 11:41:58 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-05-23 11:41:58 -0700 |
commit | 7a23ada0e5b30e4b511be7a39385121255503e2a (patch) | |
tree | cc015acd11a3ab3d13748d79aef115e1bc7b0ce8 /activesupport/test/core_ext/hash_ext_test.rb | |
parent | 82b05fbcf4869517c08fb62398b03f3f133c0a28 (diff) | |
parent | 2b5b60fc3c4251536b837937391ebdd028892b15 (diff) | |
download | rails-7a23ada0e5b30e4b511be7a39385121255503e2a.tar.gz rails-7a23ada0e5b30e4b511be7a39385121255503e2a.tar.bz2 rails-7a23ada0e5b30e4b511be7a39385121255503e2a.zip |
Merge pull request #6466 from markmcspadden/hash_deep_transform_keys
Add Hash#deep_transform_keys and Hash#deep_transform_keys! Also convert ...
Diffstat (limited to 'activesupport/test/core_ext/hash_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index e68733db8b..f13fff43d4 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -32,14 +32,17 @@ class HashExtTest < ActiveSupport::TestCase @fixnums = { 0 => 1, 1 => 2 } @nested_fixnums = { 0 => { 1 => { 2 => 3} } } @illegal_symbols = { [] => 3 } - @upcase_strings = { 'A' => 1, 'B' => 2 } @nested_illegal_symbols = { [] => { [] => 3} } + @upcase_strings = { 'A' => 1, 'B' => 2 } + @nested_upcase_strings = { 'A' => { 'B' => { 'C' => 3 } } } end def test_methods h = {} assert_respond_to h, :transform_keys assert_respond_to h, :transform_keys! + assert_respond_to h, :deep_transform_keys + assert_respond_to h, :deep_transform_keys! assert_respond_to h, :symbolize_keys assert_respond_to h, :symbolize_keys! assert_respond_to h, :deep_symbolize_keys @@ -58,12 +61,24 @@ class HashExtTest < ActiveSupport::TestCase assert_equal @upcase_strings, @mixed.transform_keys{ |key| key.to_s.upcase } end + def test_deep_transform_keys + assert_equal @nested_upcase_strings, @nested_symbols.deep_transform_keys{ |key| key.to_s.upcase } + assert_equal @nested_upcase_strings, @nested_strings.deep_transform_keys{ |key| key.to_s.upcase } + assert_equal @nested_upcase_strings, @nested_mixed.deep_transform_keys{ |key| key.to_s.upcase } + end + def test_transform_keys! assert_equal @upcase_strings, @symbols.dup.transform_keys!{ |key| key.to_s.upcase } assert_equal @upcase_strings, @strings.dup.transform_keys!{ |key| key.to_s.upcase } assert_equal @upcase_strings, @mixed.dup.transform_keys!{ |key| key.to_s.upcase } end + def test_deep_transform_keys! + assert_equal @nested_upcase_strings, @nested_symbols.deep_transform_keys!{ |key| key.to_s.upcase } + assert_equal @nested_upcase_strings, @nested_strings.deep_transform_keys!{ |key| key.to_s.upcase } + assert_equal @nested_upcase_strings, @nested_mixed.deep_transform_keys!{ |key| key.to_s.upcase } + end + def test_symbolize_keys assert_equal @symbols, @symbols.symbolize_keys assert_equal @symbols, @strings.symbolize_keys |