Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4795: test-4795.patch

File test-4795.patch, 3.0 kB (added by sd, 2 years ago)

Test this bug

  • rails/actionpack/lib/action_controller/test_process.rb

    old new  
    3939    end 
    4040 
    4141    def reset_session 
    42       @session = {} 
     42      @session = TestSession.new 
    4343    end               
    4444 
    4545    def raw_post 
     
    272272  end 
    273273 
    274274  class TestSession #:nodoc: 
    275     def initialize(attributes = {}
     275    def initialize(attributes = nil
    276276      @attributes = attributes 
    277277    end 
    278278 
    279279    def [](key) 
     280      @attributes ||= @saved_attributes || {} 
    280281      @attributes[key] 
    281282    end 
    282283 
    283284    def []=(key, value) 
     285      @attributes ||= @saved_attributes || {} 
    284286      @attributes[key] = value 
    285287    end 
    286288 
     
    289291    end 
    290292 
    291293    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 
    294300  end 
    295301   
    296302  # Essentially generates a modified Tempfile object similar to the object 
  • rails/actionpack/test/controller/session_management_test.rb

    old new  
    4444    end 
    4545  end 
    4646 
     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   
    4787  def setup 
    4888    @request, @response = ActionController::TestRequest.new, 
    4989      ActionController::TestResponse.new 
     
    91131      assert_equal CGI::Session::ActiveRecordStore, ActionController::Base.session_store 
    92132    end 
    93133  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 
    94142end