mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow you to delete cookies with options. Closes #3685 [josh, Chris Wanstrath]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7160 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
a450e769f1
commit
fd65d89e07
3 changed files with 18 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Allow you to delete cookies with options. Closes #3685 [josh, Chris Wanstrath]
|
||||||
|
|
||||||
* Allow you to render views with periods in the name. Closes #8076 [norbert]
|
* Allow you to render views with periods in the name. Closes #8076 [norbert]
|
||||||
|
|
||||||
render :partial => 'show.html.erb'
|
render :partial => 'show.html.erb'
|
||||||
|
|
|
@ -62,9 +62,11 @@ module ActionController #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
# Removes the cookie on the client machine by setting the value to an empty string
|
# Removes the cookie on the client machine by setting the value to an empty string
|
||||||
# and setting its expiration date into the past
|
# and setting its expiration date into the past. Like []=, you can pass in an options
|
||||||
def delete(name)
|
# hash to delete cookies with extra data such as a +path+.
|
||||||
set_cookie("name" => name.to_s, "value" => "", "expires" => Time.at(0))
|
def delete(name, options = {})
|
||||||
|
options.stringify_keys!
|
||||||
|
set_cookie(options.merge("name" => name.to_s, "value" => "", "expires" => Time.at(0)))
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -31,6 +31,11 @@ class CookieTest < Test::Unit::TestCase
|
||||||
cookies.delete("user_name")
|
cookies.delete("user_name")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_cookie_with_path
|
||||||
|
cookies.delete("user_name", :path => '/beaten')
|
||||||
|
render_text "hello world"
|
||||||
|
end
|
||||||
|
|
||||||
def rescue_action(e)
|
def rescue_action(e)
|
||||||
raise unless ActionController::MissingTemplate # No templates here, and we don't care about the output
|
raise unless ActionController::MissingTemplate # No templates here, and we don't care about the output
|
||||||
end
|
end
|
||||||
|
@ -85,4 +90,10 @@ class CookieTest < Test::Unit::TestCase
|
||||||
assert_equal "david", jar["user_name"]
|
assert_equal "david", jar["user_name"]
|
||||||
assert_equal nil, jar["something_else"]
|
assert_equal nil, jar["something_else"]
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue