aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
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_controller
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_controller')
-rw-r--r--actionpack/lib/action_controller/test_case.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 0f43527a56..bc4f8bb9ce 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -172,6 +172,10 @@ module ActionController
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,7 +305,11 @@ module ActionController
# and cookies, though. For sessions, you just do:
#
# @request.session[:key] = "value"
- # @request.cookies["key"] = "value"
+ # @request.cookies[:key] = "value"
+ #
+ # To clear the cookies for a test just clear the request's cookies hash:
+ #
+ # @request.cookies.clear
#
# == \Testing named routes
#
@@ -416,6 +424,7 @@ module ActionController
@controller.process_with_new_base_test(@request, @response)
@assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {}
@request.session.delete('flash') if @request.session['flash'].blank?
+ @request.cookies.merge!(@response.cookies)
@response
end