2012-04-04 30 views
1

我正在做功課,但我有非RestFul路線的問題。 我的規格是:Rspec和非RestFul路線

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 

在配置/ 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有問題。如何解決這個問題?

+2

看一看:http://guides.rubyonrails.org/routing.html#adding-collection-routes – pjumble 2012-04-04 10:33:59

+0

@pjumble,它的工作原理。我需要在路由中的某處指定param:search_term嗎? – 2012-04-04 10:54:47

回答

2

您的路線應該是這樣的

resources :movies do 
    get 'search_similar_movies', :on => :collection 
end 

match 'movies/search_similar_movies/:search_terms' => 'movies#search_similar_movies', :via => :get