From 95b8e324933ccb976ee29464d6829dff10002f4a Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 5 Jul 2023 11:41:08 -0400 Subject: [PATCH] Allow `ResourceAction#fqname=nil` to clear `ae_*` --- app/models/resource_action.rb | 2 +- spec/models/resource_action_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/models/resource_action.rb b/app/models/resource_action.rb index 7da0e6b8853..35bda5e15bd 100644 --- a/app/models/resource_action.rb +++ b/app/models/resource_action.rb @@ -56,7 +56,7 @@ def automate_queue_hash(target, override_attrs, user, open_url_task_id = nil) end def fqname=(value) - self.ae_namespace, self.ae_class, self.ae_instance, _attr_name = MiqAeEngine::MiqAePath.split(value) + self.ae_namespace, self.ae_class, self.ae_instance, _attr_name = value.blank? ? nil : MiqAeEngine::MiqAePath.split(value) end def fqname diff --git a/spec/models/resource_action_spec.rb b/spec/models/resource_action_spec.rb index 2253045aafd..3774cd6ab18 100644 --- a/spec/models/resource_action_spec.rb +++ b/spec/models/resource_action_spec.rb @@ -2,6 +2,33 @@ let(:user) { FactoryBot.create(:user_with_group) } let(:ra) { FactoryBot.create(:resource_action) } + describe "#fqname=" do + context "with an automate fully-qualified name" do + it "sets the ae_* attributes" do + ra.fqname = "/NAMESPACE/CLASS/INSTANCE" + expect(ra).to have_attributes( + :ae_namespace => "NAMESPACE", + :ae_class => "CLASS", + :ae_instance => "INSTANCE" + ) + end + end + + context "with a nil" do + context "with existing ae_attributes" do + let(:ra) { FactoryBot.create(:resource_action, :ae_namespace => "NAMESPACE", :ae_class => "CLASS", :ae_instance => "INSTANCE") } + it "clears the ae_* attributes" do + ra.fqname = nil + expect(ra).to have_attributes( + :ae_namespace => nil, + :ae_class => nil, + :ae_instance => nil + ) + end + end + end + end + context "#deliver_queue" do let(:zone_name) { "default" } let(:miq_server) { FactoryBot.create(:miq_server) }