mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #27392 from y-yagi/use_same_class_on_compact
ensure `#compact` of HWIDA to return HWIDA
This commit is contained in:
commit
98c6e4e56c
2 changed files with 14 additions and 0 deletions
|
@ -269,6 +269,10 @@ module ActiveSupport
|
|||
dup.tap { |hash| hash.transform_values!(*args, &block) }
|
||||
end
|
||||
|
||||
def compact
|
||||
dup.compact!
|
||||
end
|
||||
|
||||
# Convert to a regular hash with string keys.
|
||||
def to_hash
|
||||
_new_hash = Hash.new
|
||||
|
|
|
@ -589,6 +589,16 @@ class HashExtTest < ActiveSupport::TestCase
|
|||
assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
|
||||
end
|
||||
|
||||
def test_indifferent_compact
|
||||
hash_contain_nil_value = @strings.merge("z" => nil)
|
||||
hash = ActiveSupport::HashWithIndifferentAccess.new(hash_contain_nil_value)
|
||||
compacted_hash = hash.compact
|
||||
|
||||
assert_equal(@strings, compacted_hash)
|
||||
assert_equal(hash_contain_nil_value, hash)
|
||||
assert_instance_of ActiveSupport::HashWithIndifferentAccess, compacted_hash
|
||||
end
|
||||
|
||||
def test_indifferent_to_hash
|
||||
# Should convert to a Hash with String keys.
|
||||
assert_equal @strings, @mixed.with_indifferent_access.to_hash
|
||||
|
|
Loading…
Reference in a new issue