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

Ticket #8649: flash_preservation.diff

File flash_preservation.diff, 2.4 kB (added by fogle, 1 year ago)
  • test/ssl_requirement_test.rb

    old new  
    4444  def d 
    4545    render :nothing => true 
    4646  end 
     47   
     48  def set_flash 
     49    flash[:foo] = "bar" 
     50  end 
    4751end 
    4852 
    4953class SslRequirementTest < Test::Unit::TestCase 
     
    5357    @response   = ActionController::TestResponse.new 
    5458  end 
    5559   
     60  def test_redirect_to_https_preserves_flash 
     61    get :set_flash 
     62    get :b 
     63    assert_response :redirect 
     64    assert_equal "bar", flash[:foo] 
     65  end 
     66   
     67  def test_not_redirecting_to_https_does_not_preserve_the_flash 
     68    get :set_flash 
     69    get :d 
     70    assert_response :success 
     71    assert_nil flash[:foo] 
     72  end 
     73   
     74  def test_redirect_to_http_preserves_flash 
     75    get :set_flash 
     76    @request.env['HTTPS'] = "on" 
     77    get :d 
     78    assert_response :redirect 
     79    assert_equal "bar", flash[:foo] 
     80  end 
     81   
     82  def test_not_redirecting_to_http_does_not_preserve_the_flash 
     83    get :set_flash 
     84    @request.env['HTTPS'] = "on" 
     85    get :a 
     86    assert_response :success 
     87    assert_nil flash[:foo] 
     88  end 
     89   
    5690  def test_required_without_ssl 
    5791    assert_not_equal "on", @request.env["HTTPS"] 
    5892    get :a 
    5993    assert_response :redirect 
    60     assert_match %r{^https://}, @response.headers['location'] 
     94    assert_match %r{^https://}, @response.headers['Location'] 
    6195    get :b 
    6296    assert_response :redirect 
    63     assert_match %r{^https://}, @response.headers['location'] 
     97    assert_match %r{^https://}, @response.headers['Location'] 
    6498  end 
    6599   
    66100  def test_required_with_ssl 
     
    81115    @request.env['HTTPS'] = "on" 
    82116    get :d 
    83117    assert_response :redirect 
    84     assert_match %r{^http://}, @response.headers['location'] 
     118    assert_match %r{^http://}, @response.headers['Location'] 
    85119  end 
    86120 
    87121  def test_allowed_without_ssl 
  • lib/ssl_requirement.rb

    old new  
    5151 
    5252      if ssl_required? && !request.ssl? 
    5353        redirect_to "https://" + request.host + request.request_uri 
     54        flash.keep 
    5455        return false 
    5556      elsif request.ssl? && !ssl_required? 
    5657        redirect_to "http://" + request.host + request.request_uri 
     58        flash.keep 
    5759        return false 
    5860      end 
    5961    end