mutations can't be done without the consent of our proxy object. This
is one benefit of choosing composition over inheritance.
This commit is contained in:
parent
21df2bfc4a
commit
ffad4927b1
|
@ -188,9 +188,6 @@ module ActionDispatch
|
|||
@used.delete(k)
|
||||
end
|
||||
end
|
||||
|
||||
# clean up after keys that could have been left over by calling reject! or shift on the flash
|
||||
@used.subtract(@used - keys)
|
||||
end
|
||||
|
||||
# Convenience accessor for flash[:alert]
|
||||
|
|
|
@ -75,6 +75,7 @@ module ActionDispatch
|
|||
def test_discard_no_args
|
||||
@hash['hello'] = 'world'
|
||||
@hash.discard
|
||||
|
||||
@hash.sweep
|
||||
assert_equal({}, @hash.to_hash)
|
||||
end
|
||||
|
@ -83,8 +84,69 @@ module ActionDispatch
|
|||
@hash['hello'] = 'world'
|
||||
@hash['omg'] = 'world'
|
||||
@hash.discard 'hello'
|
||||
|
||||
@hash.sweep
|
||||
assert_equal({'omg' => 'world'}, @hash.to_hash)
|
||||
end
|
||||
|
||||
def test_keep_sweep
|
||||
@hash['hello'] = 'world'
|
||||
|
||||
@hash.sweep
|
||||
assert_equal({'hello' => 'world'}, @hash.to_hash)
|
||||
end
|
||||
|
||||
def test_update_sweep
|
||||
@hash['hello'] = 'world'
|
||||
@hash.update({'hi' => 'mom'})
|
||||
|
||||
@hash.sweep
|
||||
assert_equal({'hello' => 'world', 'hi' => 'mom'}, @hash.to_hash)
|
||||
end
|
||||
|
||||
def test_delete_sweep
|
||||
@hash['hello'] = 'world'
|
||||
@hash['hi'] = 'mom'
|
||||
@hash.delete 'hi'
|
||||
|
||||
@hash.sweep
|
||||
assert_equal({'hello' => 'world'}, @hash.to_hash)
|
||||
end
|
||||
|
||||
def test_clear_sweep
|
||||
@hash['hello'] = 'world'
|
||||
@hash.clear
|
||||
|
||||
@hash.sweep
|
||||
assert_equal({}, @hash.to_hash)
|
||||
end
|
||||
|
||||
def test_replace_sweep
|
||||
@hash['hello'] = 'world'
|
||||
@hash.replace({'hi' => 'mom'})
|
||||
|
||||
@hash.sweep
|
||||
assert_equal({'hi' => 'mom'}, @hash.to_hash)
|
||||
end
|
||||
|
||||
def test_discard_then_add
|
||||
@hash['hello'] = 'world'
|
||||
@hash['omg'] = 'world'
|
||||
@hash.discard 'hello'
|
||||
@hash['hello'] = 'world'
|
||||
|
||||
@hash.sweep
|
||||
assert_equal({'omg' => 'world', 'hello' => 'world'}, @hash.to_hash)
|
||||
end
|
||||
|
||||
def test_keep_all_sweep
|
||||
@hash['hello'] = 'world'
|
||||
@hash['omg'] = 'world'
|
||||
@hash.discard 'hello'
|
||||
@hash.keep
|
||||
|
||||
@hash.sweep
|
||||
assert_equal({'omg' => 'world', 'hello' => 'world'}, @hash.to_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue