diff --git a/app/models/mixins/retirement_mixin.rb b/app/models/mixins/retirement_mixin.rb index 363e6560eace..143137851b26 100644 --- a/app/models/mixins/retirement_mixin.rb +++ b/app/models/mixins/retirement_mixin.rb @@ -12,7 +12,7 @@ module RetirementMixin module ClassMethods def make_retire_request(*src_ids) options = {:src_ids => src_ids.presence || id} - (name + "RetireRequest").constantize.make_request(nil, options, User.current_user, true) + (name.demodulize + "RetireRequest").constantize.make_request(nil, options, User.current_user, true) end def retire(ids, options = {}) @@ -122,7 +122,7 @@ def retirement_check end end - make_retire_request if retirement_due? + self.class.make_retire_request(self.id) if retirement_due? end def retire_now(requester = nil) diff --git a/spec/models/orchestration_stack/retirement_management_spec.rb b/spec/models/orchestration_stack/retirement_management_spec.rb index a681d5894878..b0b94ad8cf43 100644 --- a/spec/models/orchestration_stack/retirement_management_spec.rb +++ b/spec/models/orchestration_stack/retirement_management_spec.rb @@ -1,18 +1,20 @@ describe "Service Retirement Management" do + let(:user) { FactoryGirl.create(:user_miq_request_approver, :userid => "admin") } before do @miq_server = EvmSpecHelper.local_miq_server @stack = FactoryGirl.create(:orchestration_stack) end it "#retirement_check" do - expect(MiqEvent).to receive(:raise_evm_event) - @stack.update_attributes(:retires_on => 90.days.ago, :retirement_warn => 60, :retirement_last_warn => nil) - expect(@stack.retirement_last_warn).to be_nil - expect(@stack).to receive(:make_retire_request).once - @stack.retirement_check - @stack.reload - expect(@stack.retirement_last_warn).not_to be_nil - expect(Time.now.utc - @stack.retirement_last_warn).to be < 30 + User.with_user(user) do + expect(MiqEvent).to receive(:raise_evm_event) + @stack.update_attributes(:retires_on => 90.days.ago, :retirement_warn => 60, :retirement_last_warn => nil) + expect(@stack.retirement_last_warn).to be_nil + @stack.retirement_check + @stack.reload + expect(@stack.retirement_last_warn).not_to be_nil + expect(Time.now.utc - @stack.retirement_last_warn).to be < 30 + end end it "#start_retirement" do diff --git a/spec/models/service/retirement_management_spec.rb b/spec/models/service/retirement_management_spec.rb index 10397c20836e..55c1c074c443 100644 --- a/spec/models/service/retirement_management_spec.rb +++ b/spec/models/service/retirement_management_spec.rb @@ -7,10 +7,10 @@ # shouldn't be running make_retire_request because it's the bimodal not from ui part it "#retirement_check" do + User.current_user = user expect(MiqEvent).to receive(:raise_evm_event) @service.update_attributes(:retires_on => 90.days.ago, :retirement_warn => 60, :retirement_last_warn => nil) expect(@service.retirement_last_warn).to be_nil - expect(@service).to receive(:make_retire_request).once @service.retirement_check @service.reload expect(@service.retirement_last_warn).not_to be_nil diff --git a/spec/models/vm/retirement_management_spec.rb b/spec/models/vm/retirement_management_spec.rb index b87a950077d5..3685a6605520 100644 --- a/spec/models/vm/retirement_management_spec.rb +++ b/spec/models/vm/retirement_management_spec.rb @@ -10,10 +10,10 @@ end it "#retirement_check" do + User.current_user = user expect(MiqEvent).to receive(:raise_evm_event).once @vm.update_attributes(:retires_on => 90.days.ago, :retirement_warn => 60, :retirement_last_warn => nil) expect(@vm.retirement_last_warn).to be_nil - expect(@vm).to receive(:make_retire_request).once @vm.retirement_check @vm.reload expect(@vm.retirement_last_warn).not_to be_nil