Ensure AR not found errors are handled in API
This commit is contained in:
parent
cd73a588b0
commit
5b9d36cb39
@ -1,11 +1,17 @@
|
||||
module API
|
||||
class ApplicationController < ::ApplicationController
|
||||
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
||||
|
||||
skip_before_filter :verify_authenticity_token
|
||||
skip_before_filter :authenticate!, only: :cor_preflight
|
||||
|
||||
before_filter :cor_filter
|
||||
before_filter :json_filter!
|
||||
|
||||
def not_found
|
||||
head :not_found
|
||||
end
|
||||
|
||||
def cor_filter
|
||||
headers['Access-Control-Allow-Origin'] = request.headers['Origin'] ?
|
||||
request.headers['Origin'] :
|
||||
|
@ -1,7 +0,0 @@
|
||||
module API
|
||||
class ErrorsController < ApplicationController
|
||||
def not_found
|
||||
head :not_found
|
||||
end
|
||||
end
|
||||
end
|
@ -8,7 +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
|
||||
match '*all', to: 'application#not_found', via: :all
|
||||
end
|
||||
|
||||
resources :playlists
|
||||
|
@ -22,7 +22,13 @@ describe 'API application' do
|
||||
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.status).to be 404
|
||||
expect(response.body).to be_empty
|
||||
end
|
||||
|
||||
it 'responds with a 404 when a resource (AR) was not found' do
|
||||
get api_playlist_path(id: 1), format: :json
|
||||
expect(response.status).to be 404
|
||||
expect(response.body).to be_empty
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user