Skip to content

Commit 5eff7a9

Browse files
authored
Merge pull request rails#27586 from maclover7/jm-fix-27584
Update `cookies` helper on all HTTP requests
2 parents 5f03172 + c5da641 commit 5eff7a9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

actionpack/lib/action_controller/test_case.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,7 @@ def determine_default_controller_class(name)
389389
# Note that the request method is not verified. The different methods are
390390
# available to make the tests more expressive.
391391
def get(action, **args)
392-
res = process(action, method: "GET", **args)
393-
cookies.update res.cookies
394-
res
392+
process(action, method: "GET", **args)
395393
end
396394

397395
# Simulate a POST request with the given parameters and set/volley the response.
@@ -519,6 +517,7 @@ def process(action, method: "GET", params: {}, session: nil, body: nil, flash: {
519517
unless @request.cookie_jar.committed?
520518
@request.cookie_jar.write(@response)
521519
cookies.update(@request.cookie_jar.instance_variable_get(:@cookies))
520+
cookies.update(@response.cookies)
522521
end
523522
end
524523
@response.prepare!

actionpack/test/dispatch/cookies_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,15 @@ def test_deleted_cookie_predicate
395395
assert_equal false, cookies.deleted?("another")
396396
end
397397

398+
# Ensure all HTTP methods have their cookies updated
399+
[:get, :post, :patch, :put, :delete, :head].each do |method|
400+
define_method("test_deleting_cookie_#{method}") do
401+
request.cookies[:user_name] = "Joe"
402+
public_send method, :logout
403+
assert_nil cookies[:user_name]
404+
end
405+
end
406+
398407
def test_deleted_cookie_predicate_with_mismatching_options
399408
cookies[:user_name] = "Joe"
400409
cookies.delete("user_name", path: "/path")

0 commit comments

Comments
 (0)