Froze rails gems
[depot.git] / vendor / rails / actionpack / test / controller / session_management_test.rb
1 require 'abstract_unit'
2
3 class SessionManagementTest < Test::Unit::TestCase
4 class SessionOffController < ActionController::Base
5 session :off
6
7 def show
8 render :text => "done"
9 end
10
11 def tell
12 render :text => "done"
13 end
14 end
15
16 class SessionOffOnController < ActionController::Base
17 session :off
18 session :on, :only => :tell
19
20 def show
21 render :text => "done"
22 end
23
24 def tell
25 render :text => "done"
26 end
27 end
28
29 class TestController < ActionController::Base
30 session :off, :only => :show
31 session :session_secure => true, :except => :show
32 session :off, :only => :conditional,
33 :if => Proc.new { |r| r.parameters[:ws] }
34
35 def show
36 render :text => "done"
37 end
38
39 def tell
40 render :text => "done"
41 end
42
43 def conditional
44 render :text => ">>>#{params[:ws]}<<<"
45 end
46 end
47
48 class SpecializedController < SessionOffController
49 session :disabled => false, :only => :something
50
51 def something
52 render :text => "done"
53 end
54
55 def another
56 render :text => "done"
57 end
58 end
59
60 class AssociationCachingTestController < ActionController::Base
61 class ObjectWithAssociationCache
62 def initialize
63 @cached_associations = false
64 end
65
66 def fetch_associations
67 @cached_associations = true
68 end
69
70 def clear_association_cache
71 @cached_associations = false
72 end
73
74 def has_cached_associations?
75 @cached_associations
76 end
77 end
78
79 def show
80 session[:object] = ObjectWithAssociationCache.new
81 session[:object].fetch_associations
82 if session[:object].has_cached_associations?
83 render :text => "has cached associations"
84 else
85 render :text => "does not have cached associations"
86 end
87 end
88
89 def tell
90 if session[:object]
91 if session[:object].has_cached_associations?
92 render :text => "has cached associations"
93 else
94 render :text => "does not have cached associations"
95 end
96 else
97 render :text => "there is no object"
98 end
99 end
100 end
101
102
103 def setup
104 @request, @response = ActionController::TestRequest.new,
105 ActionController::TestResponse.new
106 end
107
108 def test_session_off_globally
109 @controller = SessionOffController.new
110 get :show
111 assert_equal false, @request.session_options
112 get :tell
113 assert_equal false, @request.session_options
114 end
115
116 def test_session_off_then_on_globally
117 @controller = SessionOffOnController.new
118 get :show
119 assert_equal false, @request.session_options
120 get :tell
121 assert_instance_of Hash, @request.session_options
122 assert_equal false, @request.session_options[:disabled]
123 end
124
125 def test_session_off_conditionally
126 @controller = TestController.new
127 get :show
128 assert_equal false, @request.session_options
129 get :tell
130 assert_instance_of Hash, @request.session_options
131 assert @request.session_options[:session_secure]
132 end
133
134 def test_controller_specialization_overrides_settings
135 @controller = SpecializedController.new
136 get :something
137 assert_instance_of Hash, @request.session_options
138 get :another
139 assert_equal false, @request.session_options
140 end
141
142 def test_session_off_with_if
143 @controller = TestController.new
144 get :conditional
145 assert_instance_of Hash, @request.session_options
146 get :conditional, :ws => "ws"
147 assert_equal false, @request.session_options
148 end
149
150 def test_session_store_setting
151 ActionController::Base.session_store = :drb_store
152 assert_equal CGI::Session::DRbStore, ActionController::Base.session_store
153
154 if Object.const_defined?(:ActiveRecord)
155 ActionController::Base.session_store = :active_record_store
156 assert_equal CGI::Session::ActiveRecordStore, ActionController::Base.session_store
157 end
158 end
159
160 def test_process_cleanup_with_session_management_support
161 @controller = AssociationCachingTestController.new
162 get :show
163 assert_equal "has cached associations", @response.body
164 get :tell
165 assert_equal "does not have cached associations", @response.body
166 end
167
168 def test_session_is_enabled
169 @controller = TestController.new
170 get :show
171 assert_nothing_raised do
172 assert_equal false, @controller.session_enabled?
173 end
174
175 get :tell
176 assert @controller.session_enabled?
177 end
178 end