Merge pull request #16356 from gchan/add-hwia-tests
Add tests to ensure default proc is used when `HashWithIndifferentAccess' is initialized with a block
This commit is contained in:
commit
7dd452cc89
@ -586,6 +586,8 @@ def test_indifferent_to_hash
|
|||||||
roundtrip = mixed_with_default.with_indifferent_access.to_hash
|
roundtrip = mixed_with_default.with_indifferent_access.to_hash
|
||||||
assert_equal @strings, roundtrip
|
assert_equal @strings, roundtrip
|
||||||
assert_equal '1234', roundtrip.default
|
assert_equal '1234', roundtrip.default
|
||||||
|
|
||||||
|
# Ensure nested hashes are not HashWithIndiffereneAccess
|
||||||
new_to_hash = @nested_mixed.with_indifferent_access.to_hash
|
new_to_hash = @nested_mixed.with_indifferent_access.to_hash
|
||||||
assert_not new_to_hash.instance_of?(HashWithIndifferentAccess)
|
assert_not new_to_hash.instance_of?(HashWithIndifferentAccess)
|
||||||
assert_not new_to_hash["a"].instance_of?(HashWithIndifferentAccess)
|
assert_not new_to_hash["a"].instance_of?(HashWithIndifferentAccess)
|
||||||
@ -1516,6 +1518,16 @@ def test_from_trusted_xml_allows_symbol_and_yaml_types
|
|||||||
assert_equal expected, Hash.from_trusted_xml('<product><name type="yaml">:value</name></product>')
|
assert_equal expected, Hash.from_trusted_xml('<product><name type="yaml">:value</name></product>')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_should_use_default_proc_for_unknown_key
|
||||||
|
hash_wia = HashWithIndifferentAccess.new { 1 + 2 }
|
||||||
|
assert_equal 3, hash_wia[:new_key]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_use_default_proc_if_no_key_is_supplied
|
||||||
|
hash_wia = HashWithIndifferentAccess.new { 1 + 2 }
|
||||||
|
assert_equal 3, hash_wia.default
|
||||||
|
end
|
||||||
|
|
||||||
def test_should_use_default_value_for_unknown_key
|
def test_should_use_default_value_for_unknown_key
|
||||||
hash_wia = HashWithIndifferentAccess.new(3)
|
hash_wia = HashWithIndifferentAccess.new(3)
|
||||||
assert_equal 3, hash_wia[:new_key]
|
assert_equal 3, hash_wia[:new_key]
|
||||||
|
Loading…
Reference in New Issue
Block a user