views:

31

answers:

1

Hi,

I have the following route defined in routes.rb:

map.search 'fuzzyleads/search/:url', :controller => 'fuzzyleads', :action => 'search', :method => 'get'

The problem is that I cannot get this test to pass:

def test_search_route
  assert_generates "fuzzyleads/search/someurl", { :controller => "fuzzyleads", :action => "search", :url => "someurl" }
end

It does not like the url part, I get the following error:

found extras <{:url=>"someurl"}>, not <{}>

I have no idea why, can anyone see what I am doing wrong?

Cheers

Paul

A: 

The output of rake routes would help us make a little better guess. Here's how I tested using rails-2.3.8:

(1) Added your route as the second route in config/routes.rb

(2) Created the following rspec test:

it "should have valid route for fuzzyleads search" do
  route_for(:controller => 'fuzzyleads', :action => 'search', :url => 'someurl').should ==
    "/fuzzyleads/search/someurl"
end

But this failed with the following:

ActionController::RoutingError in 'FuzzyLeadsController should have valid route for fuzzyleads search'                   
No route matches "/fuzzyleads/search/someurl" with {:method=>:get}                                                  
If you're expecting this failure, we suggest {:get=>"/fuzzyleads/search/someurl"}.should_not be_routable 

But when I removed the :method restriction everything worked successfully. Adding :method => 'get' wasn't sufficient to make the test pass. I've seen similar failures when I've set conditions on routes that haven't been met, so I'd guess something similar is happening in your case.

Kaleb Pederson