diff --git a/app/controllers/api/orchestration_templates_controller.rb b/app/controllers/api/orchestration_templates_controller.rb index 29b106d5cc8..9fed6f1e880 100644 --- a/app/controllers/api/orchestration_templates_controller.rb +++ b/app/controllers/api/orchestration_templates_controller.rb @@ -3,8 +3,9 @@ class OrchestrationTemplatesController < BaseController def delete_resource(type, id, data = {}) klass = collection_class(type) resource = resource_search(id, type, klass) - super + result = super resource.raw_destroy if resource.kind_of?(OrchestrationTemplateVnfd) + result end end end diff --git a/spec/requests/api/orchestration_template_spec.rb b/spec/requests/api/orchestration_template_spec.rb index fb303ab4799..63783f80040 100644 --- a/spec/requests/api/orchestration_template_spec.rb +++ b/spec/requests/api/orchestration_template_spec.rb @@ -112,6 +112,18 @@ expect(OrchestrationTemplate.exists?(cfn.id)).to be_falsey end + it 'runs callback before_destroy on the model' do + api_basic_authorize collection_action_identifier(:orchestration_templates, :delete) + + cfn = FactoryGirl.create(:orchestration_template_vnfd_with_content) + api_basic_authorize collection_action_identifier(:orchestration_templates, :delete) + expect_any_instance_of(OrchestrationTemplateVnfd).to receive(:raw_destroy).with(no_args) # callback on the model + run_delete(orchestration_templates_url(cfn.id)) + + expect(response).to have_http_status(:no_content) + expect(OrchestrationTemplate.exists?(cfn.id)).to be_falsey + end + it 'supports multiple orchestration_template delete' do api_basic_authorize collection_action_identifier(:orchestration_templates, :delete)