1 require 'abstract_unit'
3 class SessionManagementTest
< Test
::Unit::TestCase
4 class SessionOffController
< ActionController
::Base
12 render
:text => "done"
16 class SessionOffOnController
< ActionController
::Base
18 session
:on, :only => :tell
21 render
:text => "done"
25 render
:text => "done"
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] }
36 render
:text => "done"
40 render
:text => "done"
44 render
:text => ">>>#{params[:ws]}<<<"
48 class SpecializedController
< SessionOffController
49 session
:disabled => false, :only => :something
52 render
:text => "done"
56 render
:text => "done"
60 class AssociationCachingTestController
< ActionController
::Base
61 class ObjectWithAssociationCache
63 @cached_associations = false
66 def fetch_associations
67 @cached_associations = true
70 def clear_association_cache
71 @cached_associations = false
74 def has_cached_associations
?
80 session
[:object] = ObjectWithAssociationCache
.new
81 session
[:object].fetch_associations
82 if session
[:object].has_cached_associations
?
83 render
:text => "has cached associations"
85 render
:text => "does not have cached associations"
91 if session
[:object].has_cached_associations
?
92 render
:text => "has cached associations"
94 render
:text => "does not have cached associations"
97 render
:text => "there is no object"
104 @request, @response = ActionController
::TestRequest.new
,
105 ActionController
::TestResponse.new
108 def test_session_off_globally
109 @controller = SessionOffController
.new
111 assert_equal
false, @request.session_options
113 assert_equal
false, @request.session_options
116 def test_session_off_then_on_globally
117 @controller = SessionOffOnController
.new
119 assert_equal
false, @request.session_options
121 assert_instance_of Hash
, @request.session_options
122 assert_equal
false, @request.session_options
[:disabled]
125 def test_session_off_conditionally
126 @controller = TestController
.new
128 assert_equal
false, @request.session_options
130 assert_instance_of Hash
, @request.session_options
131 assert
@request.session_options
[:session_secure]
134 def test_controller_specialization_overrides_settings
135 @controller = SpecializedController
.new
137 assert_instance_of Hash
, @request.session_options
139 assert_equal
false, @request.session_options
142 def test_session_off_with_if
143 @controller = TestController
.new
145 assert_instance_of Hash
, @request.session_options
146 get
:conditional, :ws => "ws"
147 assert_equal
false, @request.session_options
150 def test_session_store_setting
151 ActionController
::Base.session_store
= :drb_store
152 assert_equal CGI
::Session::DRbStore, ActionController
::Base.session_store
154 if Object
.const_defined
?(:ActiveRecord)
155 ActionController
::Base.session_store
= :active_record_store
156 assert_equal CGI
::Session::ActiveRecordStore, ActionController
::Base.session_store
160 def test_process_cleanup_with_session_management_support
161 @controller = AssociationCachingTestController
.new
163 assert_equal
"has cached associations", @response.body
165 assert_equal
"does not have cached associations", @response.body
168 def test_session_is_enabled
169 @controller = TestController
.new
171 assert_nothing_raised
do
172 assert_equal
false, @controller.session_enabled
?
176 assert
@controller.session_enabled
?