Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

multiple nested routes for same resource doesn't work in functional tests?

#4446

Say I have routes like so:

ActionController::Routing::Routes.draw do |map|

  map.resources :tabs do |tab|
    tab.resources :contacts, :collection => {
      :bar => :get
    }
  end

  map.resources :clients do |client|
    client.resources :contacts, :collection => {
      :foo => :get
    }
  end

  map.root :controller => 'clients', :action => 'root'

end

These routes will work as expected via the webserver, but they will fail in functional tests. Example app attached.

Reported by jemminger · April 21st, 2010 @ 02:15 AM

State: invalid
Milestone: none
Assigned to: Ryan Bigg Ryan Bigg
Importance: Low

Activity

  1. jemminger
    jemminger
    • Tag set to routing error, functional, routingerror, testing

    April 21st, 2010 @ 02:19 AM

  2. jemminger
    jemminger
    • Title changed from multiple nested routes for same route doesn't work in functional tests? to multiple nested routes for same resource doesn't work in functional tests?

    April 21st, 2010 @ 02:25 AM

  3. gnufied
    gnufied

    Your functional test has code like:

    class ContactsControllerTest < ActionController::TestCase
    
      test 'should get foo' do
        get :foo
        assert_response :success
      end
    
      test 'should get bar' do
        get :bar
        assert_response :success
      end
    end
    

    but in your routes.rb, you have marked contacts as nested resource and hence isn't accessible directly. In short, accessing contacts resource directly doesn't work from browser, doesn't work from functional tests. There ain't anything wrong with behavior.

    April 21st, 2010 @ 05:32 AM

  4. gnufied
    gnufied
    • Tag changed from routing error, functional, routingerror, testing to routing error, functional, invalid, routingerror, testing

    April 21st, 2010 @ 05:34 AM

  5. jemminger
    jemminger

    Doh, you're right. Changing the tests like so fixes it:

    test 'should get foo' do
      get :foo, :client_id => 1
      assert_response :success
    end
    
    test 'should get bar' do
      get :bar, :tab_id => 1
      assert_response :success
    end
    

    And this is how I've set up all my other tests, but for whatever reason brainfarted here and forgot.

    April 21st, 2010 @ 02:14 PM

  6. gnufied
    gnufied
    • Assigned user set to Ryan Bigg

    Please close this one.

    April 21st, 2010 @ 07:10 PM

  7. Ryan Bigg
    Ryan Bigg
    • State changed from new to invalid

    April 21st, 2010 @ 09:25 PM