diff --git a/app/controllers/api/errors_controller.rb b/app/controllers/api/errors_controller.rb new file mode 100644 index 0000000..d0c9d78 --- /dev/null +++ b/app/controllers/api/errors_controller.rb @@ -0,0 +1,7 @@ +module API + class ErrorsController < ApplicationController + def not_found + head :not_found + end + end +end diff --git a/config/routes.rb b/config/routes.rb index dd5ae1a..0c6d8b2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,7 @@ Rails.application.routes.draw do resources :sessions, only: :create resources :sounds, only: :show resources :tracks, only: :index + match '*all', to: 'errors#not_found', via: :all end resources :playlists diff --git a/spec/integration/api/application_spec.rb b/spec/integration/api/application_spec.rb index 8c7d26b..df92c4f 100644 --- a/spec/integration/api/application_spec.rb +++ b/spec/integration/api/application_spec.rb @@ -18,4 +18,12 @@ describe 'API application' do expect(response.body).to be_empty end end + + describe 'not found' do + it 'responds with a 404 when route does not exist' do + get '/api/not_found', format: :json + expect(response).to be_not_found + expect(response.body).to be_empty + end + end end