A `match`/`get` route that redirects will match against all controllers and actions when running tests #8566

Closed
nkpart opened this Issue Dec 20, 2012 · 3 comments

Comments

Projects
None yet
2 participants

nkpart commented Dec 20, 2012

I've written up the details in a gist alongside the relevant files that are needed to recreate the problem.

The crux of it is that routes like these:

get '/b' => redirect("wherever")
get 'c' => redirect("wherever")

will behave like catch-all when testing, as this output of rake routes hints at:

b GET /b(.:format) :controller#:action
c GET /c(.:format) :controller#c

Things that seem important:

  • The leading slash determines whether or not the route catches all actions
  • This doesn't use ':to' or any other of the route options that lock down controllers or actions.
Owner

pixeltrix commented Dec 20, 2012

In functional tests the controller action is called directly and not through a request so it doesn't have to match a route - use an integration test if you want make sure that the full stack works as expected.

@pixeltrix pixeltrix closed this Dec 20, 2012

nkpart commented Dec 20, 2012

If route definitions are empty the test fails. Clearly functional tests
currently require valid routing.

I'm not saying this is good practice. But either functional tests do not
require valid routing, and then the bug is that the spec fails without
valid routes, or functional tests do require valid routing and the bug is
as stated above.

On Thursday, December 20, 2012, Andrew White wrote:

In functional tests the controller action is called directly and not
through a request so it doesn't have to match a route - use an integration
test if you want make sure that the full stack works as expected.


Reply to this email directly or view it on GitHubhttps://github.com/rails/rails/issues/8566#issuecomment-11562932.

Owner

pixeltrix commented Dec 20, 2012

There has to be at least one route because ActionController::TestCase tries to synthesise a request url based upon the controller and action but if there's another route that matches then it will use that instead. I suspect what's happening is that a url like /c?controller=posts&action=index is being generated.

The only way to fix this properly is by removing the distinction between functional and integration tests which is outside the scope of a single GitHub issue, but is definitely something we're interested in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment