Rails routes, rspec

146 views Asked by At

I am attempting to create a route to a controller method, in order that it pass an rpsec condition. For some reason that escapes me, RSPEC will not accept the route.

Here is the rspec:

describe BooksController do
  describe 'searching AMZN' do
    it 'should call the model method that performs AMZN search' do
      post :search_tmdb, {:search_terms => 'hardware'}
    end

My routes file reads:

Rottenpotatoes::Application.routes.draw do

  resources :books

  post '/books/search_amzn'

  # map '/' to be a redirect to '/books'
  root :to => redirect('/books')
end

The controller action in books_controller.rb:

    def search_amzn
      @books = Books.find_in_amzn(params[:search_terms])
    end

I am clearly making an error in my route for I can't get away from this error message:

  1) MoviesController searching AMZN should call the model method that  performs AMZN search
     Failure/Error: post :search_amzn, {:search_terms => 'hardware'}
     ActionController::RoutingError:
       No route matches {:search_terms=>"hardware", :controller=>"books", :action=>"search_amzn"}
     # ./spec/controllers/books_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

Here are links to the complete files:

Routes.rb: http://pastebin.com/yKBeLLnY

Spec: http://pastebin.com/cU3nRSvE

1

There are 1 answers

5
stytown On

Change this:

post :search_tmdb, {:search_terms => 'hardware'}

to:

get :search_tmdb, {:search_terms => 'hardware'}

Also, in your routes file, change this:

post '/books/search_amzn'

to:

post '/books/search_amzn', as: :search_tmdb