rails/rails — pull request #14968 by janko-m (2014-05-04 10:55:06+00:00)
Title: Add ability to test router redirects

So far `assert_redirected_to` could only test redirects that happen on the controller level.

```ruby
# app/controllers/some_controller.rb
class SomeController < ApplicationController
def index
redirect_to "/some_path"
end
end
```
```ruby
# test/controllers/some_controller_test.rb
class SomeControllerTest < ActionController::TestCase
def test_index_redirects
get :index
assert_redirected_to "/some_path"
end
end
```

However, when wanting to test redirects that happen on the router level (in integration tests), this matcher doesn't work.

```ruby
# config/routes.rb
Blog::Application.routes.draw do
get "/foo", to: redirect("/bar")
get "/bar", to: "..."
end
```
```ruby
# test/integration/redirect_test.rb
class RedirectTest < ActionDispatch::IntegrationTest
def test_redirects
get "/foo"
assert_redirected_to "/bar"
end
end
```
```
NoMethodError: undefined method `_compute_redirect_to_location' for nil:NilClass
```

That's because this matcher expects `@controller` to be assigned, which is not the case with router redirects. This commit extends `assert_redirected_to` with the ability to test the router level redirects.