aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2016-11-11 20:05:10 +0000
committerGitHub <noreply@github.com>2016-11-11 20:05:10 +0000
commit6b830dc930a5d684c05b028757b06834df4d064d (patch)
treecce822e4496b50a6bd5b121a540447f59f59e3e4 /activesupport/test
parente4b0a5f66ebd2b7f29e4f868d2f6b2504df091e6 (diff)
parent9b103311d5d266fa509f5da8825ea5daecba1836 (diff)
downloadrails-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')
-rw-r--r--activesupport/test/abstract_unit.rb8
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb39
-rw-r--r--activesupport/test/ordered_hash_test.rb10
3 files changed, 55 insertions, 2 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb
index c26a48a490..cbe491eb73 100644
--- a/activesupport/test/abstract_unit.rb
+++ b/activesupport/test/abstract_unit.rb
@@ -22,13 +22,17 @@ if "ruby".encoding_aware?
end
end
+ENV['NO_RELOAD'] = '1'
+require 'active_support'
+require 'active_support/time'
+
require 'test/unit'
require 'empty_bool'
silence_warnings { require 'mocha/setup' }
-ENV['NO_RELOAD'] = '1'
-require 'active_support'
+# Disable available locale checks to avoid warnings running the test suite.
+I18n.enforce_available_locales = false
# Include shims until we get off 1.8.6
require 'active_support/ruby/shim' if RUBY_VERSION < '1.8.7'
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
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb
index a7fd9402c8..31eeb7f565 100644
--- a/activesupport/test/ordered_hash_test.rb
+++ b/activesupport/test/ordered_hash_test.rb
@@ -125,6 +125,15 @@ class OrderedHashTest < Test::Unit::TestCase
def test_select
assert_equal @keys, @ordered_hash.select { true }.map(&:first)
+ new_ordered_hash = @ordered_hash.select { true }
+ assert_equal @keys, new_ordered_hash.map(&:first)
+
+ if RUBY_VERSION > '1.9'
+ assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash
+ else
+ # Ruby 1.8.7 returns an Array from Hash#select
+ assert_instance_of Array, new_ordered_hash
+ end
end
def test_delete_if
@@ -147,6 +156,7 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal copy, @ordered_hash
assert !new_ordered_hash.keys.include?('pink')
assert @ordered_hash.keys.include?('pink')
+ assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash
end
def test_clear