mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #35649 from andrehjr/fix-override-of-cookies-controller-specs
Don't override @set_cookies on CookieJar#update_cookies_from_jar'
This commit is contained in:
commit
7c6343078a
2 changed files with 14 additions and 1 deletions
|
@ -338,7 +338,7 @@ module ActionDispatch
|
|||
|
||||
def update_cookies_from_jar
|
||||
request_jar = @request.cookie_jar.instance_variable_get(:@cookies)
|
||||
set_cookies = request_jar.reject { |k, _| @delete_cookies.key?(k) }
|
||||
set_cookies = request_jar.reject { |k, _| @delete_cookies.key?(k) || @set_cookies.key?(k) }
|
||||
|
||||
@cookies.update set_cookies if set_cookies
|
||||
end
|
||||
|
|
|
@ -123,6 +123,11 @@ class CookiesTest < ActionController::TestCase
|
|||
head :ok
|
||||
end
|
||||
|
||||
def set_cookie_if_not_present
|
||||
cookies["user_name"] = "alice" unless cookies["user_name"].present?
|
||||
head :ok
|
||||
end
|
||||
|
||||
def logout
|
||||
cookies.delete("user_name")
|
||||
head :ok
|
||||
|
@ -1128,6 +1133,14 @@ class CookiesTest < ActionController::TestCase
|
|||
assert_equal "bar", @controller.encrypted_cookie
|
||||
end
|
||||
|
||||
def test_cookie_override
|
||||
get :set_cookie_if_not_present
|
||||
assert_equal "alice", cookies["user_name"]
|
||||
cookies["user_name"] = "bob"
|
||||
get :set_cookie_if_not_present
|
||||
assert_equal "bob", cookies["user_name"]
|
||||
end
|
||||
|
||||
def test_signed_cookie_with_expires_set_relatively
|
||||
request.env["action_dispatch.use_cookies_with_metadata"] = true
|
||||
|
||||
|
|
Loading…
Reference in a new issue