From 46aa4e26091370f0d5ae21d636d0f21da427805e Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Fri, 4 Aug 2017 14:21:11 -0400 Subject: [PATCH] raise not found error on DELETE --- app/controllers/api/authentications_controller.rb | 2 ++ spec/requests/authentications_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/app/controllers/api/authentications_controller.rb b/app/controllers/api/authentications_controller.rb index b3e5fca10f..1553230ecb 100644 --- a/app/controllers/api/authentications_controller.rb +++ b/app/controllers/api/authentications_controller.rb @@ -22,6 +22,8 @@ def delete_resource(type, id, _data = {}) raise "Delete not supported for #{authentication_ident(auth)}" unless auth.respond_to?(:delete_in_provider_queue) task_id = auth.delete_in_provider_queue action_result(true, "Deleting #{authentication_ident(auth)}", :task_id => task_id) + rescue ActiveRecord::RecordNotFound => err + @req.method == :delete ? raise(err) : action_result(false, err.to_s) rescue => err action_result(false, err.to_s) end diff --git a/spec/requests/authentications_spec.rb b/spec/requests/authentications_spec.rb index 3429d40523..e1a1aed8d0 100644 --- a/spec/requests/authentications_spec.rb +++ b/spec/requests/authentications_spec.rb @@ -466,6 +466,14 @@ expect(response).to have_http_status(:forbidden) end + + it 'will raise an error if the authentication does not exist' do + api_basic_authorize action_identifier(:authentications, :delete, :resource_actions, :delete) + + run_delete(api_authentication_url(nil, 999_999)) + + expect(response).to have_http_status(:not_found) + end end describe 'OPTIONS /api/authentications' do