1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Dont set cookie header for deletion of unexisting data

This commit is contained in:
brainopia 2012-04-30 16:32:53 +04:00
parent dbe5162496
commit ff2667d21a
2 changed files with 26 additions and 9 deletions

View file

@ -182,8 +182,9 @@ module ActionDispatch
# and setting its expiration date into the past. Like <tt>[]=</tt>, you can pass in
# an options hash to delete cookies with extra data such as a <tt>:path</tt>.
def delete(key, options = {})
options.symbolize_keys!
return unless @cookies.has_key? key.to_s
options.symbolize_keys!
handle_options(options)
value = @cookies.delete(key.to_s)

View file

@ -38,6 +38,8 @@ class CookiesTest < ActionController::TestCase
head :ok
end
alias delete_cookie logout
def delete_cookie_with_path
cookies.delete("user_name", :path => '/beaten')
head :ok
@ -235,23 +237,33 @@ class CookiesTest < ActionController::TestCase
end
def test_expiring_cookie
request.cookies[:user_name] = 'Joe'
get :logout
assert_cookie_header "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"
assert_equal({"user_name" => nil}, @response.cookies)
end
def test_delete_cookie_with_path
request.cookies[:user_name] = 'Joe'
get :delete_cookie_with_path
assert_cookie_header "user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT"
end
def test_delete_unexisting_cookie
request.cookies.clear
get :delete_cookie
assert @response.cookies.empty?
end
def test_deleted_cookie_predicate
cookies[:user_name] = 'Joe'
cookies.delete("user_name")
assert cookies.deleted?("user_name")
assert_equal false, cookies.deleted?("another")
end
def test_deleted_cookie_predicate_with_mismatching_options
cookies[:user_name] = 'Joe'
cookies.delete("user_name", :path => "/path")
assert_equal false, cookies.deleted?("user_name", :path => "/different")
end
@ -284,6 +296,7 @@ class CookiesTest < ActionController::TestCase
end
def test_delete_and_set_cookie
request.cookies[:user_name] = 'Joe'
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)
@ -387,6 +400,7 @@ class CookiesTest < ActionController::TestCase
end
def test_deleting_cookie_with_all_domain_option
request.cookies[:user_name] = 'Joe'
get :delete_cookie_with_domain
assert_response :success
assert_cookie_header "user_name=; domain=.nextangle.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"
@ -413,6 +427,7 @@ class CookiesTest < ActionController::TestCase
end
def test_deleting_cookie_with_all_domain_option_and_tld_length
request.cookies[:user_name] = 'Joe'
get :delete_cookie_with_domain_and_tld
assert_response :success
assert_cookie_header "user_name=; domain=.nextangle.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"
@ -441,6 +456,7 @@ class CookiesTest < ActionController::TestCase
def test_deletings_cookie_with_several_preset_domains_using_one_of_these_domains
@request.host = "example2.com"
request.cookies[:user_name] = 'Joe'
get :delete_cookie_with_domains
assert_response :success
assert_cookie_header "user_name=; domain=example2.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"
@ -448,19 +464,19 @@ class CookiesTest < ActionController::TestCase
def test_deletings_cookie_with_several_preset_domains_using_other_domain
@request.host = "other-domain.com"
request.cookies[:user_name] = 'Joe'
get :delete_cookie_with_domains
assert_response :success
assert_cookie_header "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"
end
def test_cookies_hash_is_indifferent_access
get :symbol_key
assert_equal "david", cookies[:user_name]
assert_equal "david", cookies['user_name']
get :string_key
assert_equal "dhh", cookies[:user_name]
assert_equal "dhh", cookies['user_name']
get :symbol_key
assert_equal "david", cookies[:user_name]
assert_equal "david", cookies['user_name']
get :string_key
assert_equal "dhh", cookies[:user_name]
assert_equal "dhh", cookies['user_name']
end
@ -575,4 +591,4 @@ class CookiesTest < ActionController::TestCase
assert_not_equal expected.split("\n"), header
end
end
end
end