From 9a032c41dba6004b7d01f48ed24246daecdc11fa Mon Sep 17 00:00:00 2001 From: d-m-u Date: Tue, 15 Oct 2019 12:45:44 -0400 Subject: [PATCH] Generate retire requests from the base class name Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1731559 --- app/models/mixins/retirement_mixin.rb | 2 +- spec/models/service/retirement_management_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/mixins/retirement_mixin.rb b/app/models/mixins/retirement_mixin.rb index 636d3bd9931..90c150206d4 100644 --- a/app/models/mixins/retirement_mixin.rb +++ b/app/models/mixins/retirement_mixin.rb @@ -11,7 +11,7 @@ module RetirementMixin module ClassMethods def make_retire_request(*src_ids, requester, initiated_by: 'user') - klass = (name.demodulize + "RetireRequest").constantize + klass = (base_class.name.demodulize + "RetireRequest").constantize options = {:src_ids => src_ids.presence, :__initiated_by__ => initiated_by, :__request_type__ => klass.request_types.first} set_retirement_requester(options[:src_ids], requester) klass.make_request(nil, options, requester) diff --git a/spec/models/service/retirement_management_spec.rb b/spec/models/service/retirement_management_spec.rb index bde9aa8de1f..87ee16f469d 100644 --- a/spec/models/service/retirement_management_spec.rb +++ b/spec/models/service/retirement_management_spec.rb @@ -1,6 +1,7 @@ describe "Service Retirement Management" do let(:user) { FactoryBot.create(:user_miq_request_approver) } let(:service_with_owner) { FactoryBot.create(:service, :evm_owner => user) } + let(:service_ansible_playbook) { FactoryBot.create(:service_ansible_playbook) } before do @server = EvmSpecHelper.local_miq_server @@ -102,6 +103,12 @@ expect(@service.retirement_warn).to eq(options[:warn]) end + it "with a Service Ansible Playbook" do + expect(ServiceRetireRequest).to receive(:make_request) + .with(nil, {:src_ids => [service_ansible_playbook.id], :__initiated_by__ => 'user', :__request_type__ => "service_retire"}, user) + service_ansible_playbook.class.make_retire_request(service_ansible_playbook.id, user) + end + it "with one src_id" do expect(ServiceRetireRequest).to receive(:make_request) .with(nil, {:src_ids => [@service.id], :__initiated_by__ => 'user', :__request_type__ => "service_retire"}, user)