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') 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 21186270288ef3f8816cecf0aad1e1c537493bee Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 2 Nov 2016 11:44:05 +0000 Subject: Fix warning about unset I18n.enforce_available_locales --- activesupport/test/abstract_unit.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index c26a48a490..a777708e0c 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -30,6 +30,9 @@ 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' -- cgit v1.2.3 From 03e3aed60264ae0d12dfdf7a0c57044da49af148 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 2 Nov 2016 12:06:51 +0000 Subject: Fix AS::HWIA#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/core_ext/hash_ext_test.rb | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index c3a59540fb..8c032dc880 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -259,6 +259,36 @@ 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 } + + assert_equal({ "a" => 1 }, hash) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash + end + + 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 + + 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 -- 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/core_ext/hash_ext_test.rb | 23 ++++++++++++++++------- activesupport/test/ordered_hash_test.rb | 8 +++++++- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'activesupport/test') 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 -- cgit v1.2.3 From 47c1aee5641dab399d3eb0b0089f31fcdb2eee41 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Thu, 3 Nov 2016 17:23:29 +0000 Subject: Fix method redefined warnings for + and - on Time The power_assert gem has a workaround for a Ruby 2.3 bug[1] which causes method refined warnings with operator methods on Time. Work around the workaround by loading Active Support time extensions before loading the test-unit gem. [1]: https://bugs.ruby-lang.org/issues/11182 --- activesupport/test/abstract_unit.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index a777708e0c..cbe491eb73 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -22,14 +22,15 @@ 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 -- cgit v1.2.3