Ticket #4795: test-4795.patch
| File test-4795.patch, 3.0 kB (added by sd, 2 years ago) |
|---|
-
rails/actionpack/lib/action_controller/test_process.rb
old new 39 39 end 40 40 41 41 def reset_session 42 @session = {}42 @session = TestSession.new 43 43 end 44 44 45 45 def raw_post … … 272 272 end 273 273 274 274 class TestSession #:nodoc: 275 def initialize(attributes = {})275 def initialize(attributes = nil) 276 276 @attributes = attributes 277 277 end 278 278 279 279 def [](key) 280 @attributes ||= @saved_attributes || {} 280 281 @attributes[key] 281 282 end 282 283 283 284 def []=(key, value) 285 @attributes ||= @saved_attributes || {} 284 286 @attributes[key] = value 285 287 end 286 288 … … 289 291 end 290 292 291 293 def update() end 292 def close() end 293 def delete() @attributes = {} end 294 def close() 295 @saved_attributes = @attributes 296 @attributes = nil 297 end 298 def data() @attributes end 299 def delete() @attributes = nil end 294 300 end 295 301 296 302 # Essentially generates a modified Tempfile object similar to the object -
rails/actionpack/test/controller/session_management_test.rb
old new 44 44 end 45 45 end 46 46 47 class ObjectWithAssociationCache 48 def initialize 49 @cached_associations = false 50 end 51 52 def fetch_associations 53 @cached_associations = true 54 end 55 56 def clear_association_cache 57 @cached_associations = false 58 end 59 60 def has_cached_associations? 61 @cached_associations 62 end 63 end 64 65 class AssociationCachingTestController < ActionController::Base 66 def show 67 session[:object] = ObjectWithAssociationCache.new 68 session[:object].fetch_associations 69 if session[:object].has_cached_associations? 70 render_text "has cached associations" 71 else 72 render_text "does not have cached associations" 73 end 74 end 75 76 def tell 77 if session[:object] and session[:object].has_cached_associations? 78 render_text "has cached associations" 79 elsif session[:object] 80 render_text "does not have cached associations" 81 else 82 render_text "there is no object" 83 end 84 end 85 end 86 47 87 def setup 48 88 @request, @response = ActionController::TestRequest.new, 49 89 ActionController::TestResponse.new … … 91 131 assert_equal CGI::Session::ActiveRecordStore, ActionController::Base.session_store 92 132 end 93 133 end 134 135 def test_process_cleanup_with_session_management_support 136 @controller = AssociationCachingTestController.new 137 get :show 138 assert_equal "has cached associations", @response.body 139 get :tell 140 assert_equal "does not have cached associations", @response.body 141 end 94 142 end