aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxed.co>2016-11-03 14:15:29 +0000
committerAndrew White <andrew.white@unboxed.co>2016-11-03 14:15:29 +0000
commit7cef8061ab98261887001f8c6fba3f52a85dbaa8 (patch)
treefa5cedd9411eb24af3094cdc70bc7bedb1f0f6b8
parentbbe5e07f7a01d4c12767750e6280ce8f56d89070 (diff)
downloadrails-7cef8061ab98261887001f8c6fba3f52a85dbaa8.tar.gz
rails-7cef8061ab98261887001f8c6fba3f52a85dbaa8.tar.bz2
rails-7cef8061ab98261887001f8c6fba3f52a85dbaa8.zip
Adjust tests for differences between Ruby 1.8 and 1.9
Ruby 1.9 added Hash#select! and return a hash from Hash#select whereas Ruby 1.8 returned an array.
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb6
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb6
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb23
-rw-r--r--activesupport/test/ordered_hash_test.rb8
4 files changed, 25 insertions, 18 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb
index f89704d906..c02bd60fde 100644
--- a/activesupport/lib/active_support/hash_with_indifferent_access.rb
+++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -153,11 +153,7 @@ module ActiveSupport
def symbolize_keys; to_hash.symbolize_keys end
def to_options!; self end
- if RUBY_VERSION > '2.1.0'
- # On Ruby 2.1.1 and later the behavior of .select and reject changed to
- # return a new Hash instance so we need to override them to return an
- # instance of the correct class.
-
+ if RUBY_VERSION > '1.9'
def select(*args, &block)
dup.tap { |hash| hash.select!(*args, &block) }
end
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index e81bd013b6..0f9caca892 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -52,11 +52,7 @@ module ActiveSupport
true
end
- if RUBY_VERSION > '2.1.0'
- # On Ruby 2.1.1 and later the behavior of .select and reject changed to
- # return a new Hash instance so we need to override them to return an
- # instance of the correct class.
-
+ if RUBY_VERSION > '1.9'
def select(*args, &block)
dup.tap { |hash| hash.select!(*args, &block) }
end
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 8c032dc880..f29b91a324 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -262,16 +262,25 @@ class HashExtTest < Test::Unit::TestCase
def test_indifferent_select
hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select { |k, v| v == 1 }
- assert_equal({ "a" => 1 }, hash)
- assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
+ 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
- def test_indifferent_select_bang
- indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings)
- indifferent_strings.select! { |k, v| v == 1 }
+ 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
+ assert_equal({ "a" => 1 }, indifferent_strings)
+ assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
+ end
end
def test_indifferent_reject
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb
index bbaccf2594..31eeb7f565 100644
--- a/activesupport/test/ordered_hash_test.rb
+++ b/activesupport/test/ordered_hash_test.rb
@@ -127,7 +127,13 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal @keys, @ordered_hash.select { true }.map(&:first)
new_ordered_hash = @ordered_hash.select { true }
assert_equal @keys, new_ordered_hash.map(&:first)
- assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash
+
+ 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