mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
CookieJar#delete should return the key's value, consistent with a Hash
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
parent
ff8be66f24
commit
a8dc9fd27b
3 changed files with 11 additions and 3 deletions
|
@ -87,8 +87,9 @@ module ActionController #:nodoc:
|
|||
def delete(key, options = {})
|
||||
options.symbolize_keys!
|
||||
options[:path] = "/" unless options.has_key?(:path)
|
||||
super(key.to_s)
|
||||
value = super(key.to_s)
|
||||
@controller.response.delete_cookie(key, options)
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -118,6 +118,13 @@ class CookieTest < ActionController::TestCase
|
|||
assert_equal %w{1 2 3}, jar["pages"]
|
||||
end
|
||||
|
||||
def test_cookiejar_delete_removes_item_and_returns_its_value
|
||||
@request.cookies["user_name"] = "david"
|
||||
@controller.response = @response
|
||||
jar = ActionController::CookieJar.new(@controller)
|
||||
assert_equal "david", jar.delete("user_name")
|
||||
end
|
||||
|
||||
def test_delete_cookie_with_path
|
||||
get :delete_cookie_with_path
|
||||
assert_cookie_header "user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT"
|
||||
|
|
|
@ -26,11 +26,11 @@ class ActionController::TestSessionTest < ActiveSupport::TestCase
|
|||
assert_equal('value', session[:key])
|
||||
end
|
||||
|
||||
def test_calling_delete_removes_item
|
||||
def test_calling_delete_removes_item_and_returns_its_value
|
||||
session = ActionController::TestSession.new
|
||||
session[:key] = 'value'
|
||||
assert_equal('value', session[:key])
|
||||
session.delete(:key)
|
||||
assert_equal('value', session.delete(:key))
|
||||
assert_nil(session[:key])
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue