Skip to content

Commit

Permalink
Generate retire requests from the base class name
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Oct 15, 2019
1 parent c0664f7 commit 9a032c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/mixins/retirement_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions spec/models/service/retirement_management_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9a032c4

Please sign in to comment.