Rails routes issue with controller testing
I'm at a loss as to what I'm doi开发者_Python百科ng wrong here. Anyone have any insight?
Here's my routes.rb
resources :accounts do
collection do
get "search/:term/:offset/:limit.:format", :action => "search", :constraints => { :offset => /\d+/, :limit => /\d+/ }
end
end
Here's my rake routes output...
GET /accounts/search/:term/:offset/:limit.:format {:offset=>/\d+/, :action=>"search", :controller=>"accounts", :limit=>/\d+/}
Here's my test line...
get :search, :term => "Test", :offset => 0, :limit => 2
Here's my error...
ActionController::RoutingError: No route matches {:term=>"Test", :action=>"search", :controller=>"accounts", :offset=>0, :limit=>2}
Any ideas?
Thanks in advance!
I found the issues...
1) It is expecting to match on strings so instead of
:offset => 0, :limit => 2
it should be
:offset => '0', :limit => '2'
2) :format was not optional. I chose to make it an optional param, but if you encounter this you will have to pass format along if you don't make it optional.
精彩评论