Skip to content

Commit

Permalink
Revert "Improve testing of cookies in functional tests:"
Browse files Browse the repository at this point in the history
This reverts commit e2523ff.
  • Loading branch information
tenderlove committed Mar 29, 2011
1 parent f13fe8f commit ba117b2
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 102 deletions.
11 changes: 1 addition & 10 deletions actionpack/lib/action_controller/test_case.rb
Expand Up @@ -171,10 +171,6 @@ def assign_parameters(routes, controller_path, action, parameters = {})
end

def recycle!
write_cookies!
@env.delete('HTTP_COOKIE') if @cookies.blank?
@env.delete('action_dispatch.cookies')
@cookies = nil
@formats = nil
@env.delete_if { |k, v| k =~ /^(action_dispatch|rack)\.request/ }
@env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ }
Expand Down Expand Up @@ -301,11 +297,7 @@ def exists?; true; end
# and cookies, though. For sessions, you just do:
#
# @request.session[:key] = "value"
# @request.cookies[:key] = "value"
#
# To clear the cookies for a test just clear the request's cookies hash:
#
# @request.cookies.clear
# @request.cookies["key"] = "value"
#
# == Testing named routes
#
Expand Down Expand Up @@ -419,7 +411,6 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
Base.class_eval { include Testing }
@controller.process_with_new_base_test(@request, @response)
@request.session.delete('flash') if @request.session['flash'].blank?
@request.cookies.merge!(@response.cookies)
@response
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/testing/test_process.rb
Expand Up @@ -22,7 +22,7 @@ def flash
end

def cookies
@request.cookies.merge(@response.cookies).with_indifferent_access
@request.cookies.merge(@response.cookies)
end

def redirect_to_url
Expand Down
7 changes: 1 addition & 6 deletions actionpack/lib/action_dispatch/testing/test_request.rb
@@ -1,6 +1,5 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/hash/reverse_merge'
require 'rack/utils'

module ActionDispatch
class TestRequest < Request
Expand Down Expand Up @@ -77,14 +76,10 @@ def cookies
private
def write_cookies!
unless @cookies.blank?
@env['HTTP_COOKIE'] = @cookies.map { |name, value| escape_cookie(name, value) }.join('; ')
@env['HTTP_COOKIE'] = @cookies.map { |name, value| "#{name}=#{value};" }.join(' ')
end
end

def escape_cookie(name, value)
"#{Rack::Utils.escape(name)}=#{Rack::Utils.escape(value)}"
end

def delete_nil_values!
@env.delete_if { |k, v| v.nil? }
end
Expand Down
83 changes: 0 additions & 83 deletions actionpack/test/dispatch/cookies_test.rb
Expand Up @@ -94,30 +94,6 @@ def delete_cookie_with_domain
cookies.delete(:user_name, :domain => :all)
head :ok
end

def symbol_key
cookies[:user_name] = "david"
head :ok
end

def string_key
cookies['user_name'] = "david"
head :ok
end

def symbol_key_mock
cookies[:user_name] = "david" if cookies[:user_name] == "andrew"
head :ok
end

def string_key_mock
cookies['user_name'] = "david" if cookies['user_name'] == "andrew"
head :ok
end

def noop
head :ok
end
end

tests TestController
Expand Down Expand Up @@ -315,65 +291,6 @@ def test_deleting_cookie_with_all_domain_option
assert_cookie_header "user_name=; domain=.nextangle.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"
end

def test_cookies_hash_is_indifferent_access
[:symbol_key, :string_key].each do |cookie_key|
get cookie_key
assert_equal "david", cookies[:user_name]
assert_equal "david", cookies['user_name']
end
end

def test_setting_request_cookies_is_indifferent_access
@request.cookies.clear
@request.cookies[:user_name] = "andrew"
get :string_key_mock
assert_equal "david", cookies[:user_name]

@request.cookies.clear
@request.cookies['user_name'] = "andrew"
get :symbol_key_mock
assert_equal "david", cookies['user_name']
end

def test_cookies_retained_across_requests
get :symbol_key
assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
assert_equal "david", cookies[:user_name]

get :noop
assert_nil @response.headers["Set-Cookie"]
assert_equal "user_name=david", @request.env['HTTP_COOKIE']
assert_equal "david", cookies[:user_name]

get :noop
assert_nil @response.headers["Set-Cookie"]
assert_equal "user_name=david", @request.env['HTTP_COOKIE']
assert_equal "david", cookies[:user_name]
end

def test_cookies_can_be_cleared
get :symbol_key
assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
assert_equal "david", cookies[:user_name]

@request.cookies.clear
get :noop
assert_nil @response.headers["Set-Cookie"]
assert_nil @request.env['HTTP_COOKIE']
assert_nil cookies[:user_name]

get :symbol_key
assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
assert_equal "david", cookies[:user_name]
end

def test_cookies_are_escaped
@request.cookies[:user_ids] = '1;2'
get :noop
assert_equal "user_ids=1%3B2", @request.env['HTTP_COOKIE']
assert_equal "1;2", cookies[:user_ids]
end

private
def assert_cookie_header(expected)
header = @response.headers["Set-Cookie"]
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/dispatch/test_request_test.rb
Expand Up @@ -36,10 +36,10 @@ class TestRequestTest < ActiveSupport::TestCase

req.cookies["user_name"] = "david"
assert_equal({"user_name" => "david"}, req.cookies)
assert_equal "user_name=david", req.env["HTTP_COOKIE"]
assert_equal "user_name=david;", req.env["HTTP_COOKIE"]

req.cookies["login"] = "XJ-122"
assert_equal({"user_name" => "david", "login" => "XJ-122"}, req.cookies)
assert_equal %w(login=XJ-122 user_name=david), req.env["HTTP_COOKIE"].split(/; /).sort
assert_equal %w(login=XJ-122 user_name=david), req.env["HTTP_COOKIE"].split(/; ?/).sort
end
end

0 comments on commit ba117b2

Please sign in to comment.