diff --git a/config/api.yml b/config/api.yml index 95ed7f53d83..423117b9750 100644 --- a/config/api.yml +++ b/config/api.yml @@ -1971,6 +1971,8 @@ :disabled: true - :name: set_ownership :identifier: miq_template_ownership + - :name: delete + :identifier: miq_template_delete :delete: - :name: delete :identifier: miq_template_delete diff --git a/spec/requests/api/templates_spec.rb b/spec/requests/api/templates_spec.rb index c3bf962e9eb..87e808244a1 100644 --- a/spec/requests/api/templates_spec.rb +++ b/spec/requests/api/templates_spec.rb @@ -1,4 +1,34 @@ RSpec.describe "Templates API" do + describe "POST /api/templates/:c_id with DELETE action" do + it "deletes a template with an appropriate role" do + api_basic_authorize(action_identifier(:templates, :delete)) + template = FactoryGirl.create(:template) + + expect do + run_post(templates_url(template.id), :action => "delete") + end.to change(MiqTemplate, :count).by(-1) + + expected = { + "href" => a_string_matching(templates_url(template.id)), + "message" => "templates id: #{template.id} deleting", + "success" => true + } + expect(response.parsed_body).to include(expected) + expect(response).to have_http_status(:ok) + end + + it "won't delete a template without an appropriate role" do + api_basic_authorize + template = FactoryGirl.create(:template) + + expect do + run_post(templates_url(template.id), :action => "delete") + end.not_to change(MiqTemplate, :count) + + expect(response).to have_http_status(:forbidden) + end + end + describe "tags subcollection" do it "can list a template's tags" do template = FactoryGirl.create(:template)