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:
Jeffrey Hardy 2009-10-14 00:26:53 -04:00 committed by Jeremy Kemper
parent ff8be66f24
commit a8dc9fd27b
3 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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"

View File

@ -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