From 0d192acb87aae2aceb722b3f0dc1d6d00575dab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Kom=C3=A1nek?= Date: Mon, 10 Apr 2017 21:55:50 +0200 Subject: [PATCH 1/2] Method refactoring. --- .../__methods__/finish_retirement.rb | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/content/automate/ManageIQ/Cloud/Orchestration/Retirement/StateMachines/Methods.class/__methods__/finish_retirement.rb b/content/automate/ManageIQ/Cloud/Orchestration/Retirement/StateMachines/Methods.class/__methods__/finish_retirement.rb index f66816a04..0edf8b9f2 100644 --- a/content/automate/ManageIQ/Cloud/Orchestration/Retirement/StateMachines/Methods.class/__methods__/finish_retirement.rb +++ b/content/automate/ManageIQ/Cloud/Orchestration/Retirement/StateMachines/Methods.class/__methods__/finish_retirement.rb @@ -1,6 +1,31 @@ # # Description: This method marks the stack as retired # +module ManageIQ + module Automate + module Cloud + module Orchestration + module Retirement + module StateMachines + module Methods + class FinishRetirement + def initialize(handle = $evm) + @handle = handle + end -stack = $evm.root['orchestration_stack'] -stack.finish_retirement if stack + def main + stack = @handle.root['orchestration_stack'] + stack.finish_retirement if stack + end + end + end + end + end + end + end + end +end + +if __FILE__ == $PROGRAM_NAME + ManageIQ::Automate::Cloud::Orchestration::Retirement::StateMachines::Methods::FinishRetirement.new.main +end From 92a7a08cb1f6ae3048527d6359c1de757e4515dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Kom=C3=A1nek?= Date: Mon, 10 Apr 2017 21:56:07 +0200 Subject: [PATCH 2/2] New spec. --- .../__methods__/finish_retirement_spec.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/content/automate/ManageIQ/Cloud/Orchestration/Retirement/StateMachines/Methods.class/__methods__/finish_retirement_spec.rb diff --git a/spec/content/automate/ManageIQ/Cloud/Orchestration/Retirement/StateMachines/Methods.class/__methods__/finish_retirement_spec.rb b/spec/content/automate/ManageIQ/Cloud/Orchestration/Retirement/StateMachines/Methods.class/__methods__/finish_retirement_spec.rb new file mode 100644 index 000000000..4aeb5f9c3 --- /dev/null +++ b/spec/content/automate/ManageIQ/Cloud/Orchestration/Retirement/StateMachines/Methods.class/__methods__/finish_retirement_spec.rb @@ -0,0 +1,34 @@ +require_domain_file + +describe ManageIQ::Automate::Cloud::Orchestration::Retirement::StateMachines::Methods::FinishRetirement do + let(:stack) { FactoryGirl.create(:orchestration_stack_amazon) } + let(:service_orchestration) { FactoryGirl.create(:service_orchestration) } + let(:svc_model_service) { MiqAeMethodService::MiqAeServiceService.find(service_orchestration.id) } + let(:svc_model_stack) { MiqAeMethodService::MiqAeServiceOrchestrationStack.find(stack.id) } + + let(:root_hash) do + { 'service_template' => MiqAeMethodService::MiqAeServiceService.find(service_orchestration.id) } + end + + let(:root_object) do + obj = Spec::Support::MiqAeMockObject.new(root_hash) + obj["orchestration_stack"] = svc_model_stack + obj + end + + let(:ae_service) do + Spec::Support::MiqAeMockService.new(root_object).tap do |service| + current_object = Spec::Support::MiqAeMockObject.new + current_object.parent = root_object + service.object = current_object + end + end + + it "retires orchestration stack" do + described_class.new(ae_service).main + + expect(svc_model_stack.retired).to eq(true) + expect(svc_model_stack.retires_on).to be_between(Time.zone.now - 10.seconds, Time.zone.now + 1.second) + expect(svc_model_stack.retirement_state).to eq("retired") + end +end