mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Consistent behavior for session and cookies with to_h and to_hash method
This commit is contained in:
parent
148d0077c5
commit
2587cadd42
4 changed files with 11 additions and 0 deletions
|
@ -338,6 +338,9 @@ module ActionDispatch
|
|||
end
|
||||
alias :has_key? :key?
|
||||
|
||||
# Returns the cookies as Hash.
|
||||
alias :to_hash :to_h
|
||||
|
||||
def update(other_hash)
|
||||
@cookies.update other_hash.stringify_keys
|
||||
self
|
||||
|
|
|
@ -130,6 +130,7 @@ module ActionDispatch
|
|||
load_for_read!
|
||||
@delegate.dup.delete_if { |_, v| v.nil? }
|
||||
end
|
||||
alias :to_h :to_hash
|
||||
|
||||
# Updates the session with given Hash.
|
||||
#
|
||||
|
|
|
@ -36,6 +36,12 @@ class CookieJarTest < ActiveSupport::TestCase
|
|||
assert_equal "bar", request.cookie_jar.fetch(:foo)
|
||||
end
|
||||
|
||||
def test_to_hash
|
||||
request.cookie_jar["foo"] = "bar"
|
||||
assert_equal({ "foo" => "bar" }, request.cookie_jar.to_hash)
|
||||
assert_equal({ "foo" => "bar" }, request.cookie_jar.to_h)
|
||||
end
|
||||
|
||||
def test_fetch_type_error
|
||||
assert_raises(KeyError) do
|
||||
request.cookie_jar.fetch(:omglolwut)
|
||||
|
|
|
@ -22,6 +22,7 @@ module ActionDispatch
|
|||
s["foo"] = "bar"
|
||||
assert_equal "bar", s["foo"]
|
||||
assert_equal({ "foo" => "bar" }, s.to_hash)
|
||||
assert_equal({ "foo" => "bar" }, s.to_h)
|
||||
end
|
||||
|
||||
def test_create_merges_old
|
||||
|
|
Loading…
Reference in a new issue