aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Schneeman <richard.schneeman+no-recruiters@gmail.com>2017-02-23 20:34:25 -0600
committerGitHub <noreply@github.com>2017-02-23 20:34:25 -0600
commit9f46b5f096758e537fb1b7928a191a7b9b566550 (patch)
tree8a0d0d385d50935aa0b7e1beb902df90b3a36b01
parent4ed704740b7ccc8ac9cfb7b5ec62d55ac178ec97 (diff)
parentb74c7e939ae5bec5c7b98c456a3b9ceb56a0ca17 (diff)
downloadrails-9f46b5f096758e537fb1b7928a191a7b9b566550.tar.gz
rails-9f46b5f096758e537fb1b7928a191a7b9b566550.tar.bz2
rails-9f46b5f096758e537fb1b7928a191a7b9b566550.zip
Merge pull request #28138 from rwz/rwz/hwia-compact
Make HWIA#compact not return nil when no nils
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb2
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb
index 79e7feaf47..f9b269ad69 100644
--- a/activesupport/lib/active_support/hash_with_indifferent_access.rb
+++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -270,7 +270,7 @@ module ActiveSupport
end
def compact
- dup.compact!
+ dup.tap(&:compact!)
end
# Convert to a regular hash with string keys.
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 05813ad388..a6e3e59433 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -597,6 +597,16 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal(@strings, compacted_hash)
assert_equal(hash_contain_nil_value, hash)
assert_instance_of ActiveSupport::HashWithIndifferentAccess, compacted_hash
+
+ empty_hash = ActiveSupport::HashWithIndifferentAccess.new
+ compacted_hash = empty_hash.compact
+
+ assert_equal compacted_hash, empty_hash
+
+ non_empty_hash = ActiveSupport::HashWithIndifferentAccess.new(foo: :bar)
+ compacted_hash = non_empty_hash.compact
+
+ assert_equal compacted_hash, non_empty_hash
end
def test_indifferent_to_hash