This project is archived and is in readonly mode.
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 April 21st, 2010 @ 02:19 AM
- Tag set to routing error, functional, routingerror, testing
-
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 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 April 21st, 2010 @ 05:34 AM
- Tag changed from routing error, functional, routingerror, testing to routing error, functional, invalid, routingerror, testing
-
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.
-
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>