From 232a3c43ba6b9044f85de5d8296eadeda8bec288 Mon Sep 17 00:00:00 2001 From: Tim Wade Date: Tue, 28 Feb 2017 15:44:47 -0800 Subject: [PATCH] Delete services via POST Addresses https://bugzilla.redhat.com/show_bug.cgi?id=1414852 --- config/api.yml | 2 ++ spec/requests/api/services_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/config/api.yml b/config/api.yml index 2d59609c870..d103e7e46e4 100644 --- a/config/api.yml +++ b/config/api.yml @@ -1823,6 +1823,8 @@ :identifier: service_admin - :name: suspend :identifier: service_admin + - :name: delete + :identifier: service_delete :delete: - :name: delete :identifier: service_delete diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index c2feda07fbc..d3267bc619e 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -153,6 +153,34 @@ expect { svc.reload }.to raise_error(ActiveRecord::RecordNotFound) end + it "can be deleted via POST with an appropriate role" do + service = FactoryGirl.create(:service) + api_basic_authorize(action_identifier(:services, :delete)) + + expect do + run_post(services_url(service.id), :action => "delete") + end.to change(Service, :count).by(-1) + + expected = { + "success" => true, + "message" => "services id: #{service.id} deleting", + "href" => a_string_matching(services_url(service.id)) + } + expect(response.parsed_body).to include(expected) + expect(response).to have_http_status(:ok) + end + + it "won't delete a service via POST without an appropriate role" do + service = FactoryGirl.create(:service) + api_basic_authorize + + expect do + run_post(services_url(service.id), :action => "delete") + end.not_to change(Service, :count) + + expect(response).to have_http_status(:forbidden) + end + it "supports multiple resource deletes" do api_basic_authorize collection_action_identifier(:services, :delete)