This project is archived and is in readonly mode.

#4446 ✓invalid
jemminger

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

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

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.

Comments and changes to this ticket

  • jemminger

    jemminger April 21st, 2010 @ 02:19 AM

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

    jemminger April 21st, 2010 @ 02:25 AM

    • 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?”
  • gnufied

    gnufied April 21st, 2010 @ 05:32 AM

    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.

  • gnufied

    gnufied April 21st, 2010 @ 05:34 AM

    • Tag changed from routing error, functional, routingerror, testing to routing error, functional, invalid, routingerror, testing
  • jemminger

    jemminger April 21st, 2010 @ 02:14 PM

    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.

  • gnufied

    gnufied April 21st, 2010 @ 07:10 PM

    • Assigned user set to “Ryan Bigg”

    Please close this one.

  • Ryan Bigg

    Ryan Bigg April 21st, 2010 @ 09:25 PM

    • State changed from “new” to “invalid”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages