From f762cf05a55b827684b756f6affdcd54923003c0 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 2 Nov 2016 11:40:46 +0000 Subject: Fix AS::OrderHash#select and #reject on Ruby 2.1.1+ In Ruby 2.1.1 and later select and reject return a new instance of Hash rather than the subclass so we need to override them to return an instance of the correct class. --- activesupport/test/ordered_hash_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/test/ordered_hash_test.rb') diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index a7fd9402c8..bbaccf2594 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -125,6 +125,9 @@ 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) + assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash end def test_delete_if @@ -147,6 +150,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 -- cgit v1.2.3 From 7cef8061ab98261887001f8c6fba3f52a85dbaa8 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Thu, 3 Nov 2016 14:15:29 +0000 Subject: 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. --- activesupport/test/ordered_hash_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activesupport/test/ordered_hash_test.rb') 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 -- cgit v1.2.3