Ticket #1581: 1608_redirect_assertions.diff
| File 1608_redirect_assertions.diff, 3.2 kB (added by rick, 3 years ago) |
|---|
-
actionpack/test/controller/redirect_test.rb
old new 13 13 redirect_to :action => "other_host", :only_path => false, :host => 'other.test.host' 14 14 end 15 15 16 def module_redirect 17 redirect_to :controller => 'module_test/module_redirect', :action => "hello_world" 18 end 19 16 20 def rescue_errors(e) raise e end 17 21 18 22 protected … … 42 46 get :host_redirect 43 47 assert_redirected_to :action => "other_host", :only_path => false, :host => 'other.test.host' 44 48 end 49 50 def test_module_redirect 51 get :module_redirect 52 assert_redirect_url "http://test.host/module_test/module_redirect/hello_world" 53 end 54 55 def test_module_redirect_using_options 56 get :module_redirect 57 assert_redirected_to :controller => 'module_test/module_redirect', :action => 'hello_world' 58 end 45 59 end 60 61 module ModuleTest 62 class ModuleRedirectController < ::RedirectController 63 def module_redirect 64 redirect_to :controller => '/redirect', :action => "hello_world" 65 end 66 end 67 68 class ModuleRedirectTest < Test::Unit::TestCase 69 def setup 70 @controller = ModuleRedirectController.new 71 @request = ActionController::TestRequest.new 72 @response = ActionController::TestResponse.new 73 end 74 75 def test_simple_redirect 76 get :simple_redirect 77 assert_redirect_url "http://test.host/module_test/module_redirect/hello_world" 78 end 79 80 def test_redirect_with_method_reference_and_parameters 81 get :method_redirect 82 assert_redirect_url "http://test.host/module_test/module_redirect/dashboard/1?message=hello" 83 end 84 85 def test_simple_redirect_using_options 86 get :host_redirect 87 assert_redirected_to :action => "other_host", :only_path => false, :host => 'other.test.host' 88 end 89 90 def test_module_redirect 91 get :module_redirect 92 assert_redirect_url "http://test.host/redirect/hello_world" 93 end 94 95 def test_module_redirect_using_options 96 get :module_redirect 97 assert_redirected_to :controller => 'redirect', :action => "hello_world" 98 end 99 end 100 end -
actionpack/lib/action_controller/assertions.rb
old new 56 56 # such at assert_redirected_to(:controller => "weblog") will also match the redirection of 57 57 # redirect_to(:controller => "weblog", :action => "show") and so on. 58 58 def assert_redirected_to(options = {}, message=nil) 59 assert_re direct(message)59 assert_response(:redirect, message) 60 60 61 61 if options.is_a?(String) 62 62 msg = build_message(message, "expected a redirect to <?>, found one to <?>", options, @response.redirect_url) 63 64 63 url_regexp = %r{^(\w+://.*?(/|$|\?))(.*)$} 65 64 eurl, epath, url, path = [options, @response.redirect_url].collect do |url| 66 65 u, p = (url_regexp =~ url) ? [$1, $3] : [nil, url]