From 68cffbc7bfeff663728eb3c804d59ccff0597482 Mon Sep 17 00:00:00 2001 From: Greg McCullough Date: Thu, 18 May 2017 17:18:09 -0400 Subject: [PATCH 1/2] Refactor send_mail tests into sync and async tests --- .../miq_ae_service_methods_spec.rb | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb b/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb index c2fd85719..ec6895c04 100644 --- a/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb +++ b/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb @@ -20,33 +20,40 @@ def invoke_ae end end - it "#send_mail" do - options = { - :to => "wilma@bedrock.gov", - :from => "fred@bedrock.gov", - :body => "What are we having for dinner?", - :content_type => "text/fred", - :subject => "Dinner" - } - - method = "$evm.root['#{@ae_result_key}'] = $evm.execute(:send_email, #{options[:to].inspect}, #{options[:from].inspect}, #{options[:subject].inspect}, #{options[:body].inspect}, #{options[:content_type].inspect})" - @ae_method.update_attributes(:data => method) - stub_const('MiqAeMethodService::MiqAeServiceMethods::SYNCHRONOUS', true) - expect(GenericMailer).to receive(:deliver).with(:automation_notification, options).once - ae_object = invoke_ae.root(@ae_result_key) - expect(ae_object).to be_truthy + context "#send_mail" do + let(:options) do + { + :to => "wilma@bedrock.gov", + :from => "fred@bedrock.gov", + :body => "What are we having for dinner?", + :content_type => "text/fred", + :subject => "Dinner" + } + end - method = "$evm.root['#{@ae_result_key}'] = $evm.execute(:send_email, #{options[:to].inspect}, #{options[:from].inspect}, #{options[:subject].inspect}, #{options[:body].inspect}, #{options[:content_type].inspect})" - @ae_method.update_attributes(:data => method) - stub_const('MiqAeMethodService::MiqAeServiceMethods::SYNCHRONOUS', false) - expect(MiqQueue).to receive(:put).with( + it "sends mail synchronous" do + method = "$evm.root['#{@ae_result_key}'] = $evm.execute(:send_email, #{options[:to].inspect}, #{options[:from].inspect}, #{options[:subject].inspect}, #{options[:body].inspect}, #{options[:content_type].inspect})" + @ae_method.update_attributes(:data => method) + stub_const('MiqAeMethodService::MiqAeServiceMethods::SYNCHRONOUS', true) + expect(GenericMailer).to receive(:deliver).with(:automation_notification, options).once + ae_object = invoke_ae.root(@ae_result_key) + expect(ae_object).to be_truthy + end + + it "sends mail asynchronous" do + method = "$evm.root['#{@ae_result_key}'] = $evm.execute(:send_email, #{options[:to].inspect}, #{options[:from].inspect}, #{options[:subject].inspect}, #{options[:body].inspect}, #{options[:content_type].inspect})" + @ae_method.update_attributes(:data => method) + stub_const('MiqAeMethodService::MiqAeServiceMethods::SYNCHRONOUS', false) + expect(MiqQueue).to receive(:put).with( :class_name => 'GenericMailer', :method_name => "deliver", :args => [:automation_notification, options], :role => "notifier", - :zone => nil).once - ae_object = invoke_ae.root(@ae_result_key) - expect(ae_object).to be_truthy + :zone => nil + ).once + ae_object = invoke_ae.root(@ae_result_key) + expect(ae_object).to be_truthy + end end it "#snmp_trap_v1" do From 5100c61111cd7db2acd4531920edc6bbfd032c5c Mon Sep 17 00:00:00 2001 From: Greg McCullough Date: Thu, 18 May 2017 17:21:03 -0400 Subject: [PATCH 2/2] Add notifier role to miq_server so the email task gets queued Fix test after changes from PR https://github.com/ManageIQ/manageiq/pull/14801 --- .../miq_ae_method_service/miq_ae_service_methods_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb b/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb index ec6895c04..5c3cc0264 100644 --- a/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb +++ b/spec/engine/miq_ae_method_service/miq_ae_service_methods_spec.rb @@ -41,6 +41,10 @@ def invoke_ae end it "sends mail asynchronous" do + miq_server = EvmSpecHelper.local_miq_server + MiqRegion.seed + miq_server.server_roles << FactoryGirl.create(:server_role, :name => 'notifier') + method = "$evm.root['#{@ae_result_key}'] = $evm.execute(:send_email, #{options[:to].inspect}, #{options[:from].inspect}, #{options[:subject].inspect}, #{options[:body].inspect}, #{options[:content_type].inspect})" @ae_method.update_attributes(:data => method) stub_const('MiqAeMethodService::MiqAeServiceMethods::SYNCHRONOUS', false)