提交 9f46b5f0 编写于 作者: R Richard Schneeman 提交者: GitHub

Merge pull request #28138 from rwz/rwz/hwia-compact

Make HWIA#compact not return nil when no nils
......@@ -270,7 +270,7 @@ def transform_values(*args, &block)
end
def compact
dup.compact!
dup.tap(&:compact!)
end
# Convert to a regular hash with string keys.
......
......@@ -597,6 +597,16 @@ def test_indifferent_compact
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册