Ruby on rails Rspec和非RestFul路由
我正在做作业,但我对非休息路线有问题。 我的规格是:Ruby on rails Rspec和非RestFul路由,ruby-on-rails,rspec,routes,Ruby On Rails,Rspec,Routes,我正在做作业,但我对非休息路线有问题。 我的规格是: require 'spec_helper' describe MoviesController do describe 'searching TMDb' do before :each do @fake_results = [mock('Movie'), mock('Movie')] end it 'should call the model method that performs TMDb sea
require 'spec_helper'
describe MoviesController do
describe 'searching TMDb' do
before :each do
@fake_results = [mock('Movie'), mock('Movie')]
end
it 'should call the model method that performs TMDb search' do
Movie.should_receive(:find_in_tmdb).with('Star Wars').
and_return(@fake_results)
get :search_similar_movies, { :search_terms => 'Star Wars' }
end
end
end
在config/routes.rb中,我有:
resources :movies
'movies/search_similar_movies/:search_terms'
但当我运行自动测试时,它会给我以下错误:
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/routing/mapper.rb:181:in `default_controller_and_action': missing :action (ArgumentError)
很明显,config/routes.rb有问题。如何解决这个问题?您的路线应该是
resources :movies do
get 'search_similar_movies', :on => :collection
end
或
match'movies/search\u similous\u movies/:search\u terms'=>“movies#search\u similous\u movies',:via=>:get
看一看:@pjumble,它很有效。我是否需要在路由中的某个位置指定param:search_术语?