From c8dd6f224c9345b7e95cc0203b636e49412b71dc Mon Sep 17 00:00:00 2001 From: Mathias Biilmann Christensen Date: Thu, 18 Mar 2010 01:15:52 +0100 Subject: Deleting and setting a cookie in the same request was broken Made sure to remove a cookie from @deleted_cookies when set [#4211 state:committed] Signed-off-by: Jeremy Kemper --- actionpack/lib/action_dispatch/middleware/cookies.rb | 1 + actionpack/test/controller/cookie_test.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 0dc03a1a7e..ab7130ab08 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -84,6 +84,7 @@ module ActionDispatch options[:path] ||= "/" @set_cookies[key] = options + @delete_cookies.delete(key) value end diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index 908967a110..36498d13a9 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -64,6 +64,12 @@ class CookieTest < ActionController::TestCase cookies.permanent.signed[:remember_me] = 100 head :ok end + + def delete_and_set_cookie + cookies.delete :user_name + cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) } + head :ok + end end tests TestController @@ -152,6 +158,11 @@ class CookieTest < ActionController::TestCase assert_equal 100, @controller.send(:cookies).signed[:remember_me] end + def test_delete_and_set_cookie + get :delete_and_set_cookie + assert_cookie_header "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT" + assert_equal({"user_name" => "david"}, @response.cookies) + end private def assert_cookie_header(expected) -- cgit v1.2.3