diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2016-11-11 20:05:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-11 20:05:10 +0000 |
commit | 6b830dc930a5d684c05b028757b06834df4d064d (patch) | |
tree | cce822e4496b50a6bd5b121a540447f59f59e3e4 /activesupport/test/core_ext/hash_ext_test.rb | |
parent | e4b0a5f66ebd2b7f29e4f868d2f6b2504df091e6 (diff) | |
parent | 9b103311d5d266fa509f5da8825ea5daecba1836 (diff) | |
download | rails-6b830dc930a5d684c05b028757b06834df4d064d.tar.gz rails-6b830dc930a5d684c05b028757b06834df4d064d.tar.bz2 rails-6b830dc930a5d684c05b028757b06834df4d064d.zip |
Merge pull request #26962 from rails/fix-3-2-stable-on-ruby-2-3
Fix Rails 3-2-stable on Ruby 2.3.1
Diffstat (limited to 'activesupport/test/core_ext/hash_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index c3a59540fb..f29b91a324 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -259,6 +259,45 @@ class HashExtTest < Test::Unit::TestCase assert_equal hash.delete('a'), nil end + def test_indifferent_select + hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select { |k, v| v == 1 } + + if RUBY_VERSION > '1.9' + assert_equal({ "a" => 1 }, hash) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash + else + # Ruby 1.8.7 returns an Array from Hash#select + assert_equal([["a", 1]], hash) + assert_instance_of Array, hash + end + end + + if RUBY_VERSION > '1.9' + # Hash#select! was added in Ruby 1.9 + def test_indifferent_select_bang + indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings) + indifferent_strings.select! { |k, v| v == 1 } + + assert_equal({ "a" => 1 }, indifferent_strings) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings + end + end + + def test_indifferent_reject + hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).reject { |k, v| v != 1 } + + assert_equal({ "a" => 1 }, hash) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash + end + + def test_indifferent_reject_bang + indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings) + indifferent_strings.reject! { |k, v| v != 1 } + + assert_equal({ "a" => 1 }, indifferent_strings) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings + end + def test_indifferent_to_hash # Should convert to a Hash with String keys. assert_equal @strings, @mixed.with_indifferent_access.to_hash |