public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Modernize cookie testing code, and increase coverage (Heckle++) #7101 
[Kevin Clark]

git-svn-id: 
http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5978 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
technoweenie (author)
Tue Jan 16 22:53:08 -0800 2007
commit  025f8954157b685c35ad00599d66730ce9a6e1aa
tree    1a842a94a0bb8052ad31786620943fdfe8328cc5
parent  e9e86fd134e363c487cb8501fbebe7881bcf422a
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *1.13.0* (January 16th, 2007)
0
 
0
+* Modernize cookie testing code, and increase coverage (Heckle++) #7101 [Kevin Clark]
0
+
0
 * Heckling ActionController::Resources::Resource revealed that set_prefixes didn't break when :name_prefix was munged. #7081 [Kevin Clark]
0
 
0
 * Update to Prototype 1.5.0. [Sam Stephenson]
...
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
 
 
 
 
 
 
37
38
39
40
41
42
 
43
44
45
46
47
48
 
 
49
50
51
52
53
 
 
54
55
56
57
58
 
 
59
60
61
62
63
 
 
64
65
66
67
68
 
 
69
70
71
72
73
 
74
75
76
77
78
79
 
 
 
 
 
 
 
 
 
 
 
 
 
80
...
4
5
6
 
7
8
9
10
 
11
12
13
14
 
15
16
17
18
 
19
20
21
22
23
 
24
25
26
27
 
28
29
 
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
 
48
49
50
51
52
 
 
53
54
55
56
57
 
 
58
59
60
61
62
 
 
63
64
65
66
67
 
 
68
69
70
71
72
 
 
73
74
 
 
 
 
 
75
76
77
78
79
80
81
82
83
84
85
86
87
88
0
@@ -4,78 +4,86 @@
0
   class TestController < ActionController::Base
0
     def authenticate_with_deprecated_writer
0
       cookie "name" => "user_name", "value" => "david"
0
- render_text "hello world"
0
     end
0
 
0
     def authenticate
0
       cookies["user_name"] = "david"
0
- render_text "hello world"
0
     end
0
 
0
     def authenticate_for_fourten_days
0
       cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) }
0
- render_text "hello world"
0
     end
0
 
0
     def authenticate_for_fourten_days_with_symbols
0
       cookies[:user_name] = { :value => "david", :expires => Time.local(2005, 10, 10) }
0
- render_text "hello world"
0
     end
0
 
0
     def set_multiple_cookies
0
       cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) }
0
       cookies["login"] = "XJ-122"
0
- render_text "hello world"
0
     end
0
 
0
     def access_frozen_cookies
0
       cookies["will"] = "work"
0
- render_text "hello world"
0
     end
0
 
0
- def rescue_action(e) raise end
0
+ def logout
0
+ cookies.delete("user_name")
0
+ end
0
+
0
+ def rescue_action(e)
0
+ raise unless ActionController::MissingTemplate # No templates here, and we don't care about the output
0
+ end
0
   end
0
 
0
   def setup
0
     @request = ActionController::TestRequest.new
0
     @response = ActionController::TestResponse.new
0
 
0
+ @controller = TestController.new
0
     @request.host = "www.nextangle.com"
0
   end
0
 
0
   def test_setting_cookie_with_deprecated_writer
0
- @request.action = "authenticate_with_deprecated_writer"
0
- assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david") ], process_request.headers["cookie"]
0
+ get :authenticate_with_deprecated_writer
0
+ assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david") ], @response.headers["cookie"]
0
   end
0
 
0
   def test_setting_cookie
0
- @request.action = "authenticate"
0
- assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david") ], process_request.headers["cookie"]
0
+ get :authenticate
0
+ assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david") ], @response.headers["cookie"]
0
   end
0
 
0
   def test_setting_cookie_for_fourteen_days
0
- @request.action = "authenticate_for_fourten_days"
0
- assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], process_request.headers["cookie"]
0
+ get :authenticate_for_fourten_days
0
+ assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"]
0
   end
0
 
0
   def test_setting_cookie_for_fourteen_days_with_symbols
0
- @request.action = "authenticate_for_fourten_days"
0
- assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], process_request.headers["cookie"]
0
+ get :authenticate_for_fourten_days
0
+ assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"]
0
   end
0
 
0
   def test_multiple_cookies
0
- @request.action = "set_multiple_cookies"
0
- assert_equal 2, process_request.headers["cookie"].size
0
+ get :set_multiple_cookies
0
+ assert_equal 2, @response.cookies.size
0
   end
0
 
0
   def test_setting_test_cookie
0
- @request.action = "access_frozen_cookies"
0
- assert_nothing_raised { process_request }
0
+ assert_nothing_raised { get :access_frozen_cookies }
0
   end
0
-
0
- private
0
- def process_request
0
- TestController.process(@request, @response)
0
- end
0
+
0
+ def test_expiring_cookie
0
+ get :logout
0
+ assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "", "expires" => Time.at(0)) ], @response.headers["cookie"]
0
+ end
0
+
0
+ def test_cookiejar_accessor
0
+ @request.cookies["user_name"] = CGI::Cookie.new("name" => "user_name", "value" => "david", "expires" => Time.local(2025, 10, 10))
0
+ @controller.request = @request
0
+ jar = ActionController::CookieJar.new(@controller)
0
+ assert_equal "david", jar["user_name"]
0
+ assert_equal nil, jar["something_else"]
0
+ end
0
 end

Comments

    No one has commented yet.