diff options
author | Mark McSpadden <markmcspadden@gmail.com> | 2012-05-23 12:31:35 -0500 |
---|---|---|
committer | Mark McSpadden <markmcspadden@gmail.com> | 2012-05-23 13:11:06 -0500 |
commit | 2b5b60fc3c4251536b837937391ebdd028892b15 (patch) | |
tree | 94f6cbd72dba9be3f9bf15e422f6d45642dc7122 /activesupport/test/core_ext | |
parent | 541429fbe49b0671adb3842ab1818230d670ef9f (diff) | |
download | rails-2b5b60fc3c4251536b837937391ebdd028892b15.tar.gz rails-2b5b60fc3c4251536b837937391ebdd028892b15.tar.bz2 rails-2b5b60fc3c4251536b837937391ebdd028892b15.zip |
Add Hash#deep_transform_keys and Hash#deep_transform_keys! Also convert deep_*_keys to use deep_transform_keys.
Diffstat (limited to 'activesupport/test/core_ext')
-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 |