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

Changeset 3459

Show
Ignore:
Timestamp:
01/22/06 01:52:23 (3 years ago)
Author:
david
Message:

Raise a RedirectBackError if redirect_to :back is called when theres no HTTP_REFERER defined (closes #3049) [kevin.clark@gmail.com]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r3457 r3459  
    11*SVN* 
     2 
     3* Raise a RedirectBackError if redirect_to :back is called when there's no HTTP_REFERER defined #3049 [kevin.clark@gmail.com] 
    24 
    35* Treat timestamps like datetimes for scaffolding purposes #3388 [Maik Schmidt] 
  • trunk/actionpack/lib/action_controller/base.rb

    r3442 r3459  
    3737    DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and only once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\". Finally, note that to cause a before filter to halt execution of the rest of the filter chain, the filter must return false, explicitly, so \"render(...) and return false\"."  
    3838 
     39    def initialize(message = nil) 
     40      super(message || DEFAULT_MESSAGE) 
     41    end 
     42  end 
     43  class RedirectBackError < ActionControllerError #:nodoc: 
     44    DEFAULT_MESSAGE = 'No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify @request.env["HTTP_REFERER"].' 
     45   
    3946    def initialize(message = nil) 
    4047      super(message || DEFAULT_MESSAGE) 
     
    781788           
    782789          when :back 
    783             redirect_to(request.env["HTTP_REFERER"]
     790            request.env["HTTP_REFERER"] ? redirect_to(request.env["HTTP_REFERER"]) : raise(RedirectBackError
    784791 
    785792          else 
  • trunk/actionpack/test/controller/redirect_test.rb

    r2848 r3459  
    2828 
    2929  def rescue_errors(e) raise e end 
     30     
     31  def rescue_action(e) raise end 
    3032   
    3133  protected 
     
    7779    assert_redirect_url "http://www.example.com/coming/from" 
    7880  end 
     81   
     82  def test_redirect_to_back_with_no_referer 
     83    assert_raises(ActionController::RedirectBackError) { 
     84      @request.env["HTTP_REFERER"] = nil 
     85      get :redirect_to_back 
     86    } 
     87  end 
    7988end 
    8089 
  • trunk/actionpack/test/template/url_helper_test.rb

    r2572 r3459  
    111111  def test_link_tag_using_post_javascript 
    112112    assert_dom_equal( 
    113       "<a href=\"http://www.example.com\" onclick=\"f = document.createElement('form'); document.body.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit();return false;\">Hello</a>", 
     113      "<a href=\"http://www.example.com\" onclick=\"var f = document.createElement('form'); document.body.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit();return false;\">Hello</a>", 
    114114      link_to("Hello", "http://www.example.com", :post => true) 
    115115    ) 
     
    118118  def test_link_tag_using_post_javascript_and_confirm 
    119119    assert_dom_equal( 
    120       "<a href=\"http://www.example.com\" onclick=\"if (confirm('Are you serious?')) { f = document.createElement('form'); document.body.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit(); };return false;\">Hello</a>", 
     120      "<a href=\"http://www.example.com\" onclick=\"if (confirm('Are you serious?')) { var f = document.createElement('form'); document.body.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit(); };return false;\">Hello</a>", 
    121121      link_to("Hello", "http://www.example.com", :post => true, :confirm => "Are you serious?") 
    122122    )