diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-11-26 02:04:35 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-11-26 02:04:35 +0000 |
commit | d0c90331f19004f9f297989785f1516631ea0fc3 (patch) | |
tree | b10ab040e13e1b6dc659364857ae91d8b128dc58 /actionpack/test/controller | |
parent | b62937acbd5c14d6499f4e45f4b821043a826044 (diff) | |
download | rails-d0c90331f19004f9f297989785f1516631ea0fc3.tar.gz rails-d0c90331f19004f9f297989785f1516631ea0fc3.tar.bz2 rails-d0c90331f19004f9f297989785f1516631ea0fc3.zip |
Added a new container for cookies that makes them more intuative to use. The old methods of cookie and @cookies have been deprecated.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@20 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/cookie_test.rb | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index d3099bcd99..1bd17c5c2f 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -2,11 +2,27 @@ require File.dirname(__FILE__) + '/../abstract_unit' class CookieTest < Test::Unit::TestCase class TestController < ActionController::Base - def authenticate + def authenticate_with_deprecated_writer cookie "name" => "user_name", "value" => "david" render_text "hello world" end + def authenticate + cookies["user_name"] = "david" + render_text "hello world" + end + + def authenticate_for_fourten_days + cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) } + render_text "hello world" + end + + def set_multiple_cookies + cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) } + cookies["login"] = "XJ-122" + render_text "hello world" + end + def access_frozen_cookies @cookies["wont"] = "work" end @@ -21,12 +37,27 @@ class CookieTest < Test::Unit::TestCase @request.host = "www.nextangle.com" end + def test_setting_cookie_with_deprecated_writer + @request.action = "authenticate_with_deprecated_writer" + assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david") ], process_request.headers["cookie"] + end + def test_setting_cookie @request.action = "authenticate" assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david") ], process_request.headers["cookie"] end - def test_setting_cookie + def test_setting_cookie_for_fourteen_days + @request.action = "authenticate_for_fourten_days" + assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], process_request.headers["cookie"] + end + + def test_multiple_cookies + @request.action = "set_multiple_cookies" + assert_equal 2, process_request.headers["cookie"].size + end + + def test_setting_cookie_on_frozen_instance_variable @request.action = "access_frozen_cookies" assert_raises(TypeError) { process_request } end |