Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't seem to match nested routes #273

Closed
wwkeyboard opened this issue Nov 27, 2010 · 9 comments
Closed

Can't seem to match nested routes #273

wwkeyboard opened this issue Nov 27, 2010 · 9 comments

Comments

@wwkeyboard
Copy link

When setting up a basic rails 3 application it seems like rspec-rails is unable to test nested routes. I've included a basic setup that should enable anyone to reproduce the error. This is present on both 2.1.0 and on master. One quick work around is to create a route directly to the controller.

routes.rb :

Testrspec2::Application.routes.draw do
  resources :two do
    resources :one
  end
end

one_controller_spec.rb :

require 'spec_helper'

describe OneController do
  it "should be successful" do
    get "index"
    response.should be_success
  end
end

one_controller.rb :

class OneController < ApplicationController
end
@dchelimsky
Copy link
Contributor

Keep in mind that rspec-rails is a thin wrapper for Rails' own testing framework. What happens if you do the same thing in a Rails functional test?

require 'test_helper'

class OneControllerTest < ActionController::TestCase
  test "get index should be success" do
    get "index"
    assert_response :success
  end
end

@RobertDober
Copy link

I stumbled on the same problem just minutes ago. You were right David, it seems to be a rails issue. Here is the output of the unit test you proposed, just in case I missed something

ruby -I. functional/activities_controller_test.rb 2010-12-01 12:24:28
Loaded suite functional/activities_controller_test
Started
E
Finished in 0.138036 seconds.

  1. Error:
    test_get_index_should_be_success(ActivitiesControllerTest):
    ActionController::RoutingError: No route matches {:controller=>"activities"}
    /home/robert/.rvm/gems/ruby-1.9.2-p0@rails3/gems/actionpack-3.0.0/lib

/action_dispatch/routing/route_set.rb:424:in `raise_routing_error'
/home/robert/.rvm/gems/ruby-1.9.2-p0@rails3/gems/actionpack-3.0.0/lib

/action_dispatch/routing/route_set.rb:406:in rescue in generate' /home/robert/.rvm/gems/ruby-1.9.2-p0@rails3/gems/actionpack-3.0.0/lib /action_dispatch/routing/route_set.rb:395:ingenerate'
/home/robert/.rvm/gems/ruby-1.9.2-p0@rails3/gems/actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:453:in generate' /home/robert/.rvm/gems/ruby-1.9.2-p0@rails3/gems/actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:449:ingenerate_extras'
/home/robert/.rvm/gems/ruby-1.9.2-p0@rails3/gems/actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:445:in extra_keys' /home/robert/.rvm/gems/ruby-1.9.2-p0@rails3/gems/actionpack-3.0.0/lib/action_controller/test_case.rb:136:inassign_parameters'
/home/robert/.rvm/gems/ruby-1.9.2-p0@rails3/gems/actionpack-3.0.0/lib/action_controller/test_case.rb:395:in process' /home/robert/.rvm/gems/ruby-1.9.2-p0@rails3/gems/actionpack-3.0.0/lib/action_controller/test_case.rb:343:inget'
functional/activities_controller_test.rb:5:in `block in class:ActivitiesControllerTest'

1 tests, 0 assertions, 0 failures, 1 errors, 0 skips

Test run options: --seed 52769


Here is the setup

Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.0)
Using builder (2.1.2)
Using i18n (0.4.2)
Using activemodel (3.0.0)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.6)
Using tzinfo (0.3.23)
Using actionpack (3.0.0)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.10)
Using actionmailer (3.0.0)
Using arel (1.0.1)
Using activerecord (3.0.0)
Using activeresource (3.0.0)
Using archive-tar-minitar (0.5.2)
Using bcrypt-ruby (2.1.2)
Using bundler (1.0.7)
Using celerity (0.8.4)
Using culerity (0.2.12)
Using nokogiri (1.4.4)
Using ffi (0.6.3)
Using childprocess (0.1.4)
Using json_pure (1.4.6)
Using rubyzip (0.9.4)
Using selenium-webdriver (0.1.1)
Using xpath (0.1.2)
Using capybara (0.4.0)
Using columnize (0.3.2)
Using warden (1.0.2)
Using devise (1.1.5)
Using diff-lcs (1.1.2)
Using hirb (0.3.5)
Using thor (0.14.6)
Using railties (3.0.0)
Using rails (3.0.0)
Using jquery-rails (0.2.5)
Using ruby_core_source (0.1.4)
Using linecache19 (0.5.11)
Using mysql2 (0.2.6)
Using nifty-generators (0.4.2)
Using rspec-core (2.2.1)
Using rspec-expectations (2.2.0)
Using rspec-mocks (2.2.0)
Using rspec (2.2.0)
Using rspec-rails (2.2.0)
Using ruby-debug-base19 (0.11.24)
Using ruby-debug19 (0.11.6)
Using shoulda (2.11.3)
Using wirble (0.1.3)

@RobertDober
Copy link

Please forgive, and forget, the mess above

This is more readable:


I stumbled on the same problem just minutes ago. You were right David, it seems to be a rails issue. Here is the output of the unit test you proposed, just in case I missed something

https://gist.github.com/723367

@dchelimsky
Copy link
Contributor

Please raise this issue in the rails tracker if it's not already there:

http://rails.lighthouseapp.com/

@wwkeyboard
Copy link
Author

I am also able to duplicate the problem, I will bubble this up to rails after work(unless someone is really excited and does it before then).

David and Robert, thanks for your help!

@RobertDober
Copy link

redirect "thanks", :to => "David"

I just created the ticket.

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6097-testing-nested-routes

@RobertDober
Copy link

Just a taught though

get :index

cannot work on a nested route, are we aware of this?
What we want is that the automated tests do something like

get :index, <name_of_parent>_id => 42

right?

Cheers
Robert

@peppyheppy
Copy link

Any resolution on this?

@dchelimsky
Copy link
Contributor

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants