aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/test_request_test.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2011-03-30 00:46:27 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2011-06-04 07:09:11 +0100
commitd4658d86fe7b037f2105e798a5717e22ca55d61d (patch)
tree51902717a0b8881534a9e978db7502eff9a1e26c /actionpack/test/dispatch/test_request_test.rb
parent64325a82427120cf7659c80e1b67ca1ffb01ebc4 (diff)
downloadrails-d4658d86fe7b037f2105e798a5717e22ca55d61d.tar.gz
rails-d4658d86fe7b037f2105e798a5717e22ca55d61d.tar.bz2
rails-d4658d86fe7b037f2105e798a5717e22ca55d61d.zip
Refactor ActionController::TestCase cookies
Assigning cookies for test cases should now use cookies[], e.g: cookies[:email] = 'user@example.com' get :index assert_equal 'user@example.com', cookies[:email] To clear the cookies, use clear, e.g: cookies.clear get :index assert_nil cookies[:email] We now no longer write out HTTP_COOKIE and the cookie jar is persistent between requests so if you need to manipulate the environment for your test you need to do it before the cookie jar is created.
Diffstat (limited to 'actionpack/test/dispatch/test_request_test.rb')
-rw-r--r--actionpack/test/dispatch/test_request_test.rb15
1 files changed, 9 insertions, 6 deletions
diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb
index 81a8c24525..c520fb59ec 100644
--- a/actionpack/test/dispatch/test_request_test.rb
+++ b/actionpack/test/dispatch/test_request_test.rb
@@ -34,12 +34,15 @@ class TestRequestTest < ActiveSupport::TestCase
assert_equal({}, req.cookies)
assert_equal nil, req.env["HTTP_COOKIE"]
- req.cookies["user_name"] = "david"
- assert_equal({"user_name" => "david"}, req.cookies)
- assert_equal "user_name=david", req.env["HTTP_COOKIE"]
+ req.cookie_jar["user_name"] = "david"
+ assert_cookies({"user_name" => "david"}, req.cookie_jar)
- 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
+ req.cookie_jar["login"] = "XJ-122"
+ assert_cookies({"user_name" => "david", "login" => "XJ-122"}, req.cookie_jar)
end
+
+ private
+ def assert_cookies(expected, cookie_jar)
+ assert_equal(expected, cookie_jar.instance_variable_get("@cookies"))
+ end
end