aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/testing/test_request.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2011-03-06 12:49:44 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2011-03-06 12:49:44 +0000
commit31f09f9dbc1b8e598fc82d86b622167bfc01d18a (patch)
tree8568ac4781f047ab912f873b226ac4ee13df7717 /actionpack/lib/action_dispatch/testing/test_request.rb
parente00867bc437b6a681491ef59e13423051e6d98f0 (diff)
downloadrails-31f09f9dbc1b8e598fc82d86b622167bfc01d18a.tar.gz
rails-31f09f9dbc1b8e598fc82d86b622167bfc01d18a.tar.bz2
rails-31f09f9dbc1b8e598fc82d86b622167bfc01d18a.zip
Improve testing of cookies in functional tests:
- cookies can be set using string or symbol keys - cookies are preserved across calls to get, post, etc. - cookie names and values are escaped - cookies can be cleared using @request.cookies.clear [#6272 state:resolved]
Diffstat (limited to 'actionpack/lib/action_dispatch/testing/test_request.rb')
-rw-r--r--actionpack/lib/action_dispatch/testing/test_request.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb
index cf440a1fad..822adb6a47 100644
--- a/actionpack/lib/action_dispatch/testing/test_request.rb
+++ b/actionpack/lib/action_dispatch/testing/test_request.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/hash/reverse_merge'
+require 'rack/utils'
module ActionDispatch
class TestRequest < Request
@@ -77,10 +78,14 @@ module ActionDispatch
private
def write_cookies!
unless @cookies.blank?
- @env['HTTP_COOKIE'] = @cookies.map { |name, value| "#{name}=#{value};" }.join(' ')
+ @env['HTTP_COOKIE'] = @cookies.map { |name, value| escape_cookie(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