Permalink
Browse files

Merge pull request #31844 from igorkasyanchuk/add_to_hash_and_to_h_fo…

…r_session_and_cookies

Consistent behavior for session and cookies with to_h and to_hash method
  • Loading branch information...
kamipo committed Jan 31, 2018
1 parent 7e06e7a commit 50a62499e41dfffc2903d468e8b47acebaf9b500
@@ -1,3 +1,8 @@
* Add alias method `to_hash` to `to_h` for `cookies`.
Add alias method `to_h` to `to_hash` for `session`.
*Igor Kasyanchuk*
* Update the default HSTS max-age value to 31536000 seconds (1 year)
to meet the minimum max-age requirement for https://hstspreload.org/.
@@ -338,6 +338,9 @@ def key?(name)
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 @@ def to_hash
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 @@ def test_key_is_to_s
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 @@ def test_to_hash
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

0 comments on commit 50a6249

Please sign in to comment.