diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-05-22 16:57:45 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-05-22 17:05:44 -0700 |
commit | f9dde8fe4e14e7750e9a00c666b052bb409ead05 (patch) | |
tree | b9cbb097c0f9b44ec0ba2b5a902a39e615d54986 /actionpack/test/controller/cookie_test.rb | |
parent | c90f613ad68253cb253bf47cb812f9e027c35d10 (diff) | |
download | rails-f9dde8fe4e14e7750e9a00c666b052bb409ead05.tar.gz rails-f9dde8fe4e14e7750e9a00c666b052bb409ead05.tar.bz2 rails-f9dde8fe4e14e7750e9a00c666b052bb409ead05.zip |
Port cookies to new base
Diffstat (limited to 'actionpack/test/controller/cookie_test.rb')
-rw-r--r-- | actionpack/test/controller/cookie_test.rb | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index 0f22714071..39d0017dd8 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -4,44 +4,48 @@ class CookieTest < ActionController::TestCase class TestController < ActionController::Base def authenticate cookies["user_name"] = "david" + head :ok end def set_with_with_escapable_characters cookies["that & guy"] = "foo & bar => baz" + head :ok end def authenticate_for_fourteen_days cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) } + head :ok end def authenticate_for_fourteen_days_with_symbols cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) } + head :ok end def set_multiple_cookies cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) } cookies["login"] = "XJ-122" + head :ok end def access_frozen_cookies cookies["will"] = "work" + head :ok end def logout cookies.delete("user_name") + head :ok end def delete_cookie_with_path cookies.delete("user_name", :path => '/beaten') - render :text => "hello world" + head :ok end def authenticate_with_http_only cookies["user_name"] = { :value => "david", :httponly => true } - end - - def rescue_action(e) - raise unless ActionView::MissingTemplate # No templates here, and we don't care about the output + head :ok end end @@ -54,38 +58,38 @@ class CookieTest < ActionController::TestCase def test_setting_cookie get :authenticate - assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] + assert_cookie_header "user_name=david; path=/" assert_equal({"user_name" => "david"}, @response.cookies) end def test_setting_with_escapable_characters get :set_with_with_escapable_characters - assert_equal "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/", @response.headers["Set-Cookie"] + assert_cookie_header "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/" assert_equal({"that & guy" => "foo & bar => baz"}, @response.cookies) end def test_setting_cookie_for_fourteen_days get :authenticate_for_fourteen_days - assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"] + assert_cookie_header "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT" assert_equal({"user_name" => "david"}, @response.cookies) end def test_setting_cookie_for_fourteen_days_with_symbols get :authenticate_for_fourteen_days_with_symbols - assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"] + assert_cookie_header "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT" assert_equal({"user_name" => "david"}, @response.cookies) end def test_setting_cookie_with_http_only get :authenticate_with_http_only - assert_equal "user_name=david; path=/; HttpOnly", @response.headers["Set-Cookie"] + assert_cookie_header "user_name=david; path=/; HttpOnly" assert_equal({"user_name" => "david"}, @response.cookies) end def test_multiple_cookies get :set_multiple_cookies assert_equal 2, @response.cookies.size - assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT\nlogin=XJ-122; path=/", @response.headers["Set-Cookie"] + assert_cookie_header "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT\nlogin=XJ-122; path=/" assert_equal({"login" => "XJ-122", "user_name" => "david"}, @response.cookies) end @@ -95,7 +99,7 @@ class CookieTest < ActionController::TestCase def test_expiring_cookie get :logout - assert_equal "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT", @response.headers["Set-Cookie"] + assert_cookie_header "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT" assert_equal({"user_name" => nil}, @response.cookies) end @@ -116,6 +120,16 @@ class CookieTest < ActionController::TestCase def test_delete_cookie_with_path get :delete_cookie_with_path - assert_equal "user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT", @response.headers["Set-Cookie"] + assert_cookie_header "user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT" end + + private + def assert_cookie_header(expected) + header = @response.headers["Set-Cookie"] + if header.respond_to?(:to_str) + assert_equal expected, header + else + assert_equal expected.split("\n"), header + end + end end |