Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert "Improve testing of cookies in functional tests:"

This reverts commit e2523ff.
  • Loading branch information...
commit ba117b2b43a00c282bb4905fb003dd169a5312df 1 parent f13fe8f
Aaron Patterson tenderlove authored
11 actionpack/lib/action_controller/test_case.rb
View
@@ -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/ }
@@ -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
#
@@ -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
2  actionpack/lib/action_dispatch/testing/test_process.rb
View
@@ -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
7 actionpack/lib/action_dispatch/testing/test_request.rb
View
@@ -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
@@ -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
83 actionpack/test/dispatch/cookies_test.rb
View
@@ -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
@@ -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"]
4 actionpack/test/dispatch/test_request_test.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.