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

Ticket #2291: component_flash_fix.2322.2.diff

File component_flash_fix.2322.2.diff, 2.7 kB (added by rick, 3 years ago)

added test to make sure flash was cleared properly.

  • actionpack/test/controller/components_test.rb

    old new  
    2525    render_text "Yes, ma'am" 
    2626  end 
    2727 
     28  def set_flash 
     29    render_component(:controller => 'callee', :action => 'set_flash') 
     30  end 
     31 
     32  def use_flash 
     33    render_component(:controller => 'callee', :action => 'use_flash') 
     34  end 
     35 
    2836  def rescue_action(e) raise end 
    2937end 
    3038 
     
    3644  def blowing_up 
    3745    render_text "It's game over, man, just game over, man!", "500 Internal Server Error" 
    3846  end 
     47   
     48  def set_flash 
     49    flash[:notice] = 'My stoney baby' 
     50    render :text => 'flash is set' 
     51  end 
     52   
     53  def use_flash 
     54    render :text => flash[:notice] || 'no flash' 
     55  end 
    3956 
    4057  def rescue_action(e) raise end 
    4158end 
     
    7188    get :internal_caller 
    7289    assert_equal "Are you there? Yes, ma'am", @response.body 
    7390  end 
     91   
     92  def test_flash 
     93    get :set_flash 
     94    assert_equal 'My stoney baby', flash[:notice] 
     95    get :use_flash 
     96    assert_equal 'My stoney baby', @response.body 
     97    get :use_flash 
     98    assert_equal 'no flash', @response.body 
     99  end 
    74100end 
  • actionpack/lib/action_controller/components.rb

    old new  
    4343   
    4444    private 
    4545      def component_response(options, reuse_response = true) 
    46         component_class(options).process(request_for_component(options), reuse_response ? @response : response_for_component
     46        component_class(options).process(request_for_component(options), reuse_response ? @response : response_for_component, true
    4747      end 
    4848     
    4949      def component_class(options) 
  • actionpack/lib/action_controller/flash.rb

    old new  
    2828      super 
    2929      base.before_filter(:fire_flash) 
    3030      base.after_filter(:sweep_flash) 
     31      class << base 
     32        def process(request, response, keep_flash = false) 
     33          ctrl = new 
     34          if keep_flash 
     35            class << ctrl 
     36              private 
     37                def fire_flash 
     38                end 
     39                 
     40                def sweep_flash 
     41                end 
     42            end 
     43          end 
     44          ctrl.process(request, response) 
     45        end 
     46      end 
    3147    end 
    3248 
    3349    class FlashNow #:nodoc: