functional tests RoutingError when route exists #4401

Closed
kenmazaika opened this Issue Jan 10, 2012 · 6 comments

Comments

Projects
None yet
6 participants
@kenmazaika
Contributor

kenmazaika commented Jan 10, 2012

I was looking to add a parameter that should be present base on the route. This works in a controller and when viewing the page, but when writing a functional test it causes the route to never be found.

resources :awesomes, :awesome_level => 100, :only => [:index]

causes the awesomes controller index action to have param[:awesome_level] set to 100, but now I cannot write a functional test for this action. When I write a functional test it causes:

ActionController::RoutingError: No route matches {:controller=>"awesomes"}

To happen when I do not believe it should. If the :awesome_level is removed from the routes file, the test passes.

Example of the bug is in a bare rails project, with only the problem located at the github repo here:

https://github.com/kenmazaika/routing-error-rails

@kenmazaika

This comment has been minimized.

Show comment
Hide comment
@kenmazaika

kenmazaika Jan 10, 2012

Contributor

I should note that when you go to:

http://localhost:4567/awesomes

the following is rendered:

{"awesome_level":100}

Contributor

kenmazaika commented Jan 10, 2012

I should note that when you go to:

http://localhost:4567/awesomes

the following is rendered:

{"awesome_level":100}

@ghost ghost assigned tenderlove Jan 11, 2012

@isaacsanders

This comment has been minimized.

Show comment
Hide comment
@isaacsanders

isaacsanders May 1, 2012

Contributor

Is this still an issue?

Contributor

isaacsanders commented May 1, 2012

Is this still an issue?

@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Sep 15, 2012

Member

The test app is on Rails 3.0.10. I updated it to 3.2.8, and the problem still persists.

I noticed the app was using JRuby. I updated the Gemfile to include sqlite3 and used MRI, and I get the same failure, with this backtrace:

  1) Error:
test_awesomes_index(AwesomesControllerTest):
ActionController::RoutingError: No route matches {:controller=>"awesomes"}
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:532:in `raise_routing_error'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:528:in `rescue in generate'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:520:in `generate'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:561:in `generate'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:557:in `generate_extras'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:553:in `extra_keys'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/test_case.rb:147:in `assign_parameters'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/test_case.rb:459:in `process'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/test_case.rb:49:in `process'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/test_case.rb:386:in `get'
    /Users/steve/tmp/routing-error-rails/test/functional/awesomes_controller_test.rb:5:in `block in <class:AwesomesControllerTest>'

Member

steveklabnik commented Sep 15, 2012

The test app is on Rails 3.0.10. I updated it to 3.2.8, and the problem still persists.

I noticed the app was using JRuby. I updated the Gemfile to include sqlite3 and used MRI, and I get the same failure, with this backtrace:

  1) Error:
test_awesomes_index(AwesomesControllerTest):
ActionController::RoutingError: No route matches {:controller=>"awesomes"}
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:532:in `raise_routing_error'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:528:in `rescue in generate'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:520:in `generate'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:561:in `generate'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:557:in `generate_extras'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:553:in `extra_keys'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/test_case.rb:147:in `assign_parameters'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/test_case.rb:459:in `process'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/test_case.rb:49:in `process'
    /Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/test_case.rb:386:in `get'
    /Users/steve/tmp/routing-error-rails/test/functional/awesomes_controller_test.rb:5:in `block in <class:AwesomesControllerTest>'

@robertjwhitney

This comment has been minimized.

Show comment
Hide comment
@robertjwhitney

robertjwhitney Mar 11, 2013

Contributor

Same on 3.2.12

ActionDispatch::Routing::RoutSet::Generator#generate is throwing Journey::Router::RoutingError when trying to execute:

  path, params = @set.formatter.generate(:path_info, named_route, options, recall, PARAMETERIZE)
  # ...

Which is being rescued:

# lib/action_dispatch/routing/route_set.rb:520
def generate
  path, params = @set.formatter.generate(:path_info, named_route, options, recall, PARAMETERIZE)

  raise_routing_error unless path

  return [path, params.keys] if @extras

  [path, params]
rescue Journey::Router::RoutingError
  raise_routing_error
end

but after that I found I was chasing it all over the place. Could probably use some guidance on where to look next.

Contributor

robertjwhitney commented Mar 11, 2013

Same on 3.2.12

ActionDispatch::Routing::RoutSet::Generator#generate is throwing Journey::Router::RoutingError when trying to execute:

  path, params = @set.formatter.generate(:path_info, named_route, options, recall, PARAMETERIZE)
  # ...

Which is being rescued:

# lib/action_dispatch/routing/route_set.rb:520
def generate
  path, params = @set.formatter.generate(:path_info, named_route, options, recall, PARAMETERIZE)

  raise_routing_error unless path

  return [path, params.keys] if @extras

  [path, params]
rescue Journey::Router::RoutingError
  raise_routing_error
end

but after that I found I was chasing it all over the place. Could probably use some guidance on where to look next.

@robertjwhitney

This comment has been minimized.

Show comment
Hide comment
@robertjwhitney

robertjwhitney Mar 12, 2013

Contributor

chased it to rails/actionpack/lib/action_controller/test_case.rb:151

def assign_parameters(routes, controller_path, action, parameters = {})
  # ...
  extra_keys = routes.extra_keys(parameters)
  # ...
Contributor

robertjwhitney commented Mar 12, 2013

chased it to rails/actionpack/lib/action_controller/test_case.rb:151

def assign_parameters(routes, controller_path, action, parameters = {})
  # ...
  extra_keys = routes.extra_keys(parameters)
  # ...
@pixeltrix

This comment has been minimized.

Show comment
Hide comment
@pixeltrix

pixeltrix Apr 22, 2013

Member

This is fixed by f1d8f2a in Rails 4.

You also need to make it an explicit default - unknown options are treated as constraints, e.g:

resources :awesomes, only: [:index], defaults: { awesome_level: 100 }
Member

pixeltrix commented Apr 22, 2013

This is fixed by f1d8f2a in Rails 4.

You also need to make it an explicit default - unknown options are treated as constraints, e.g:

resources :awesomes, only: [:index], defaults: { awesome_level: 100 }

@pixeltrix pixeltrix closed this Apr 22, 2013

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