Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
@@ -171,10 +171,6 @@ def assign_parameters(routes, controller_path, action, parameters = {})
171 171 end
172 172
173 173 def recycle!
174   - write_cookies!
175   - @env.delete('HTTP_COOKIE') if @cookies.blank?
176   - @env.delete('action_dispatch.cookies')
177   - @cookies = nil
178 174 @formats = nil
179 175 @env.delete_if { |k, v| k =~ /^(action_dispatch|rack)\.request/ }
180 176 @env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ }
@@ -301,11 +297,7 @@ def exists?; true; end
301 297 # and cookies, though. For sessions, you just do:
302 298 #
303 299 # @request.session[:key] = "value"
304   - # @request.cookies[:key] = "value"
305   - #
306   - # To clear the cookies for a test just clear the request's cookies hash:
307   - #
308   - # @request.cookies.clear
  300 + # @request.cookies["key"] = "value"
309 301 #
310 302 # == Testing named routes
311 303 #
@@ -419,7 +411,6 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
419 411 Base.class_eval { include Testing }
420 412 @controller.process_with_new_base_test(@request, @response)
421 413 @request.session.delete('flash') if @request.session['flash'].blank?
422   - @request.cookies.merge!(@response.cookies)
423 414 @response
424 415 end
425 416
2  actionpack/lib/action_dispatch/testing/test_process.rb
@@ -22,7 +22,7 @@ def flash
22 22 end
23 23
24 24 def cookies
25   - @request.cookies.merge(@response.cookies).with_indifferent_access
  25 + @request.cookies.merge(@response.cookies)
26 26 end
27 27
28 28 def redirect_to_url
7 actionpack/lib/action_dispatch/testing/test_request.rb
... ... @@ -1,6 +1,5 @@
1 1 require 'active_support/core_ext/object/blank'
2 2 require 'active_support/core_ext/hash/reverse_merge'
3   -require 'rack/utils'
4 3
5 4 module ActionDispatch
6 5 class TestRequest < Request
@@ -77,14 +76,10 @@ def cookies
77 76 private
78 77 def write_cookies!
79 78 unless @cookies.blank?
80   - @env['HTTP_COOKIE'] = @cookies.map { |name, value| escape_cookie(name, value) }.join('; ')
  79 + @env['HTTP_COOKIE'] = @cookies.map { |name, value| "#{name}=#{value};" }.join(' ')
81 80 end
82 81 end
83 82
84   - def escape_cookie(name, value)
85   - "#{Rack::Utils.escape(name)}=#{Rack::Utils.escape(value)}"
86   - end
87   -
88 83 def delete_nil_values!
89 84 @env.delete_if { |k, v| v.nil? }
90 85 end
83 actionpack/test/dispatch/cookies_test.rb
@@ -94,30 +94,6 @@ def delete_cookie_with_domain
94 94 cookies.delete(:user_name, :domain => :all)
95 95 head :ok
96 96 end
97   -
98   - def symbol_key
99   - cookies[:user_name] = "david"
100   - head :ok
101   - end
102   -
103   - def string_key
104   - cookies['user_name'] = "david"
105   - head :ok
106   - end
107   -
108   - def symbol_key_mock
109   - cookies[:user_name] = "david" if cookies[:user_name] == "andrew"
110   - head :ok
111   - end
112   -
113   - def string_key_mock
114   - cookies['user_name'] = "david" if cookies['user_name'] == "andrew"
115   - head :ok
116   - end
117   -
118   - def noop
119   - head :ok
120   - end
121 97 end
122 98
123 99 tests TestController
@@ -315,65 +291,6 @@ def test_deleting_cookie_with_all_domain_option
315 291 assert_cookie_header "user_name=; domain=.nextangle.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"
316 292 end
317 293
318   - def test_cookies_hash_is_indifferent_access
319   - [:symbol_key, :string_key].each do |cookie_key|
320   - get cookie_key
321   - assert_equal "david", cookies[:user_name]
322   - assert_equal "david", cookies['user_name']
323   - end
324   - end
325   -
326   - def test_setting_request_cookies_is_indifferent_access
327   - @request.cookies.clear
328   - @request.cookies[:user_name] = "andrew"
329   - get :string_key_mock
330   - assert_equal "david", cookies[:user_name]
331   -
332   - @request.cookies.clear
333   - @request.cookies['user_name'] = "andrew"
334   - get :symbol_key_mock
335   - assert_equal "david", cookies['user_name']
336   - end
337   -
338   - def test_cookies_retained_across_requests
339   - get :symbol_key
340   - assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
341   - assert_equal "david", cookies[:user_name]
342   -
343   - get :noop
344   - assert_nil @response.headers["Set-Cookie"]
345   - assert_equal "user_name=david", @request.env['HTTP_COOKIE']
346   - assert_equal "david", cookies[:user_name]
347   -
348   - get :noop
349   - assert_nil @response.headers["Set-Cookie"]
350   - assert_equal "user_name=david", @request.env['HTTP_COOKIE']
351   - assert_equal "david", cookies[:user_name]
352   - end
353   -
354   - def test_cookies_can_be_cleared
355   - get :symbol_key
356   - assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
357   - assert_equal "david", cookies[:user_name]
358   -
359   - @request.cookies.clear
360   - get :noop
361   - assert_nil @response.headers["Set-Cookie"]
362   - assert_nil @request.env['HTTP_COOKIE']
363   - assert_nil cookies[:user_name]
364   -
365   - get :symbol_key
366   - assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
367   - assert_equal "david", cookies[:user_name]
368   - end
369   -
370   - def test_cookies_are_escaped
371   - @request.cookies[:user_ids] = '1;2'
372   - get :noop
373   - assert_equal "user_ids=1%3B2", @request.env['HTTP_COOKIE']
374   - assert_equal "1;2", cookies[:user_ids]
375   - end
376   -
377 294 private
378 295 def assert_cookie_header(expected)
379 296 header = @response.headers["Set-Cookie"]
4 actionpack/test/dispatch/test_request_test.rb
@@ -36,10 +36,10 @@ class TestRequestTest < ActiveSupport::TestCase
36 36
37 37 req.cookies["user_name"] = "david"
38 38 assert_equal({"user_name" => "david"}, req.cookies)
39   - assert_equal "user_name=david", req.env["HTTP_COOKIE"]
  39 + assert_equal "user_name=david;", req.env["HTTP_COOKIE"]
40 40
41 41 req.cookies["login"] = "XJ-122"
42 42 assert_equal({"user_name" => "david", "login" => "XJ-122"}, req.cookies)
43   - assert_equal %w(login=XJ-122 user_name=david), req.env["HTTP_COOKIE"].split(/; /).sort
  43 + assert_equal %w(login=XJ-122 user_name=david), req.env["HTTP_COOKIE"].split(/; ?/).sort
44 44 end
45 45 end

0 comments on commit ba117b2

Please sign in to comment.
Something went wrong with that request. Please try again.