views:

52

answers:

1

I get the following error when testing a named route

1) Failure:
test_settings_route(ProjectsControllerTest) [/test/functional/projects_controller_test.rb:15]:
The generated path <"/projects/1/edit"> did not match <"/projects/1/settings">

Here's the test and what I put in my routes file

# projects_controller_test.rb
require 'test_helper'
class ProjectsControllerTest < ActionController::TestCase
def test_settings_route
  assert_routing '/projects/1/settings', :controller => 'projects', :action => 'edit', :id => '1'
end

# routes.rb
map.settings '/projects/:id/settings', :controller => 'projects', :action => 'edit'

With that entry in my routes file my application behaves as expected - which is to render the project's edit template when /projects/1/settings is requested - but I just don't understand how to get my test green.

I've also tried the shoulda macro with the same result

should_route :get, "/projects/1/settings", :controller => 'projects', :action => 'edit', :id => '1'
A: 

I had map.resources :projects above my named route in routes.rb. Moving my named route to the top fixed my test.

Brandon Toone