From c6515e93ed4ee0826e184e606efa12a67fe30221 Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Thu, 25 Apr 2019 17:51:55 -0400 Subject: [PATCH 1/4] Provide placeholder params for the ConversionHost#disable method. --- app/models/conversion_host/configurations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/conversion_host/configurations.rb b/app/models/conversion_host/configurations.rb index a8b2b6246b4..7fd2753a713 100644 --- a/app/models/conversion_host/configurations.rb +++ b/app/models/conversion_host/configurations.rb @@ -100,7 +100,7 @@ def disable_queue(auth_user = nil) self.class.queue_configuration('disable', id, resource, {}, auth_user) end - def disable + def disable(_params, _auth_user = nil) resource_info = "type=#{resource.class.name} id=#{resource.id}" _log.debug("Disabling a conversion_host #{resource_info}") From d3baa3e2269ec2e55928ce921f3f816205afec93 Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Thu, 25 Apr 2019 18:13:11 -0400 Subject: [PATCH 2/4] Set default value to nil for disable method. --- app/models/conversion_host/configurations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/conversion_host/configurations.rb b/app/models/conversion_host/configurations.rb index 7fd2753a713..b3fc8a0b118 100644 --- a/app/models/conversion_host/configurations.rb +++ b/app/models/conversion_host/configurations.rb @@ -100,7 +100,7 @@ def disable_queue(auth_user = nil) self.class.queue_configuration('disable', id, resource, {}, auth_user) end - def disable(_params, _auth_user = nil) + def disable(_params = nil, _auth_user = nil) resource_info = "type=#{resource.class.name} id=#{resource.id}" _log.debug("Disabling a conversion_host #{resource_info}") From b65640453c0325c47ed2da605915c280884c2abc Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Fri, 26 Apr 2019 13:29:13 -0400 Subject: [PATCH 3/4] Added a disable_queue spec. --- .../conversion_host/configurations_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/models/conversion_host/configurations_spec.rb b/spec/models/conversion_host/configurations_spec.rb index 1744d967e4a..87d9606a9b9 100644 --- a/spec/models/conversion_host/configurations_spec.rb +++ b/spec/models/conversion_host/configurations_spec.rb @@ -143,6 +143,16 @@ context "#disable_queue" do let(:op) { 'disable' } + let(:expected_notify) do + { + :type => :conversion_host_config_success, + :options => { + :op_name => "disable", + :op_arg => "type=#{vm.class.name} id=#{vm.id}" + } + } + end + it "to queue with a task" do task_id = conversion_host.disable_queue expect(MiqTask.find(task_id)).to have_attributes(:name => expected_task_action) @@ -156,6 +166,13 @@ :zone => conversion_host.resource.ext_management_system.my_zone ) end + + it "calls the disable method if delivered" do + allow_any_instance_of(ConversionHost).to receive(:disable_conversion_host_role) + expect(Notification).to receive(:create).with(expected_notify) + conversion_host.disable_queue + expect(MiqQueue.first.deliver).to include("ok") + end end end end From 6941105053dac1d57e010a8e3624666a38906314 Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Fri, 26 Apr 2019 14:12:55 -0400 Subject: [PATCH 4/4] Update mocks to avoid allow_any_instance_of. --- spec/models/conversion_host/configurations_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/models/conversion_host/configurations_spec.rb b/spec/models/conversion_host/configurations_spec.rb index 87d9606a9b9..69e09398941 100644 --- a/spec/models/conversion_host/configurations_spec.rb +++ b/spec/models/conversion_host/configurations_spec.rb @@ -168,7 +168,9 @@ end it "calls the disable method if delivered" do - allow_any_instance_of(ConversionHost).to receive(:disable_conversion_host_role) + allow(conversion_host).to receive(:disable_conversion_host_role) + allow(ConversionHost).to receive(:find).with(conversion_host.id).and_return(conversion_host) + expect(Notification).to receive(:create).with(expected_notify) conversion_host.disable_queue expect(MiqQueue.first.deliver).to include("ok")