Permalink
Browse files

Merge delete-with-options for cookies from trunk to release

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@7161 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent b29caa5 commit d81ac8d6f30fa8a277c60a80a8d81e34de51b61b @NZKoz NZKoz committed Jul 1, 2007
Showing with 18 additions and 3 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +5 −3 actionpack/lib/action_controller/cookies.rb
  3. +11 −0 actionpack/test/controller/cookie_test.rb
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Allow you to delete cookies with options. Closes #3685 [josh, Chris Wanstrath]
+
* Deprecate pagination. Install the classic_pagination plugin for forward compatibility, or move to the superior will_paginate plugin. #8157 [Mislav Marohnic]
* Fix filtered parameter logging with nil parameter values. #8422 [choonkeat]
View
8 actionpack/lib/action_controller/cookies.rb
@@ -62,9 +62,11 @@ def []=(name, options)
end
# Removes the cookie on the client machine by setting the value to an empty string
- # and setting its expiration date into the past
- def delete(name)
- set_cookie("name" => name.to_s, "value" => "", "expires" => Time.at(0))
+ # and setting its expiration date into the past. Like []=, you can pass in an options
+ # hash to delete cookies with extra data such as a +path+.
+ def delete(name, options = {})
+ options.stringify_keys!
+ set_cookie(options.merge("name" => name.to_s, "value" => "", "expires" => Time.at(0)))
end
private
View
11 actionpack/test/controller/cookie_test.rb
@@ -31,6 +31,11 @@ def logout
cookies.delete("user_name")
end
+ def delete_cookie_with_path
+ cookies.delete("user_name", :path => '/beaten')
+ render_text "hello world"
+ end
+
def rescue_action(e)
raise unless ActionController::MissingTemplate # No templates here, and we don't care about the output
end
@@ -85,4 +90,10 @@ def test_cookiejar_accessor
assert_equal "david", jar["user_name"]
assert_equal nil, jar["something_else"]
end
+
+ def test_delete_cookie_with_path
+ get :delete_cookie_with_path
+ assert_equal "/beaten", @response.headers["cookie"].first.path
+ assert_not_equal "/", @response.headers["cookie"].first.path
+ end
end

0 comments on commit d81ac8d

Please sign in to comment.