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

Changeset 1332

Show
Ignore:
Timestamp:
05/19/05 19:19:58 (3 years ago)
Author:
david
Message:

Fixed assert_redirect_to to work with redirect_to_path #869 [Nicholas Seckar]

Files:

Legend:

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

    r1328 r1332  
    11*SVN* 
     2 
     3* Fixed assert_redirect_to to work with redirect_to_path #869 [Nicholas Seckar] 
    24 
    35* Fixed escaping of :method option in remote_form_tag #1218 [Rick Olson] 
  • trunk/actionpack/lib/action_controller/assertions.rb

    r1291 r1332  
    5252        assert_redirect(message) 
    5353 
    54         msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>)", @response.redirected_to) 
    55         assert_block(msg) do 
    56           if options.is_a?(Symbol) 
    57             @response.redirected_to == options 
    58           else 
    59             options.keys.all? do |k|  
    60               options[k] == (@response.redirected_to[k].respond_to?(:to_param) ? @response.redirected_to[k].to_param : @response.redirected_to[k] unless @response.redirected_to[k].nil?) 
     54        if options.is_a?(String) 
     55          msg = build_message(message, "expected a redirect to <?>, found one to <?>", options, @response.redirect_url) 
     56           
     57          url_regexp = %r{^(\w+://.*?(/|$|\?))(.*)$} 
     58          eurl, epath, url, path = [options, @response.redirect_url].collect do |url| 
     59            u, p = (url_regexp =~ url) ? [$1, $3] : [nil, url] 
     60            [u, (p[0..0] == '/') ? p : '/' + p] 
     61          end.flatten 
     62 
     63          if eurl && url then assert_equal(eurl, url, msg) 
     64          else assert_equal(epath, path, msg) 
     65          end 
     66        else 
     67          msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>)", 
     68                              @response.redirected_to || @response.redirect_url) 
     69 
     70          assert_block(msg) do 
     71            if options.is_a?(Symbol) 
     72              @response.redirected_to == options 
     73            else 
     74              options.keys.all? do |k|  
     75                options[k] == (@response.redirected_to[k].respond_to?(:to_param) ? @response.redirected_to[k].to_param : @response.redirected_to[k] unless @response.redirected_to[k].nil?) 
     76              end 
    6177            end 
    6278          end 
  • trunk/actionpack/test/controller/action_pack_assertions_test.rb

    r1189 r1332  
    2020  def redirect_to_controller() redirect_to :controller => "elsewhere", :action => "flash_me"; end 
    2121 
     22  def redirect_to_path() redirect_to '/some/path' end 
     23   
    2224  # a redirect to an external location 
    2325  def redirect_external() redirect_to_url "http://www.rubyonrails.org"; end 
     
    369371    assert_raises(RuntimeError, "Can't follow redirects outside of current controller (elsewhere)") { follow_redirect } 
    370372  end 
     373 
     374  def test_redirected_to_url_leadling_slash 
     375    process :redirect_to_path 
     376    assert_redirected_to '/some/path' 
     377  end 
     378  def test_redirected_to_url_no_leadling_slash 
     379    process :redirect_to_path 
     380    assert_redirected_to 'some/path' 
     381  end 
     382  def test_redirected_to_url_full_url 
     383    process :redirect_to_path 
     384    assert_redirected_to 'http://test.host/some/path' 
     385  end 
    371386end 
    372387