aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorPavel Pravosud <pavel@pravosud.com>2017-02-23 14:43:56 -0800
committerPavel Pravosud <pavel@pravosud.com>2017-02-23 15:24:22 -0800
commitb74c7e939ae5bec5c7b98c456a3b9ceb56a0ca17 (patch)
tree3aeb9e6cd1f3b2517485c2c510010576d5ebabe2 /activesupport
parent18afe45d7c564e5b9bc453bbe06a2aa78aebe246 (diff)
downloadrails-b74c7e939ae5bec5c7b98c456a3b9ceb56a0ca17.tar.gz
rails-b74c7e939ae5bec5c7b98c456a3b9ceb56a0ca17.tar.bz2
rails-b74c7e939ae5bec5c7b98c456a3b9ceb56a0ca17.zip
Make HWIA#compact not return nil when no nils
Diffstat (limited to 'activesupport')
-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