From 0353aeb064d13c2e1df5221a9979d347bcb5ea36 Mon Sep 17 00:00:00 2001 From: Martin Povolny Date: Sat, 23 Dec 2017 11:48:22 +0100 Subject: [PATCH] Merge pull request #2899 from pkomanek/ae_git_import_multiple_domains ae_import multiple domains (cherry picked from commit d4b7f57a8f543a28b3049f757b58ef7a97bbb2b0) --- app/services/git_based_domain_import_service.rb | 6 +++++- .../git_based_domain_import_service_spec.rb | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/services/git_based_domain_import_service.rb b/app/services/git_based_domain_import_service.rb index 797a525a83f..d96b636e46d 100644 --- a/app/services/git_based_domain_import_service.rb +++ b/app/services/git_based_domain_import_service.rb @@ -94,7 +94,11 @@ def import(git_repo_id, branch_or_tag, tenant_id) task = MiqTask.wait_for_taskid(task_id) domain = task.task_results - error_message = _("Selected branch or tag does not contain a valid domain") + error_message = if task.message == _('multiple domains') + _('Selected branch or tag contains more than one domain') + else + _('Selected branch or tag does not contain a valid domain') + end raise MiqException::Error, error_message unless domain.kind_of?(MiqAeDomain) domain.update_attribute(:enabled, true) end diff --git a/spec/services/git_based_domain_import_service_spec.rb b/spec/services/git_based_domain_import_service_spec.rb index bb34404bf65..e00b24a3467 100644 --- a/spec/services/git_based_domain_import_service_spec.rb +++ b/spec/services/git_based_domain_import_service_spec.rb @@ -68,6 +68,7 @@ allow(domain).to receive(:update_attribute).with(:enabled, true) allow(MiqTask).to receive(:wait_for_taskid).with(task.id).and_return(task) allow(User).to receive(:current_user).and_return(user) + allow(task).to receive(:message).and_return(nil) end context "when git branches that match the given name exist" do @@ -91,7 +92,6 @@ allow(task).to receive(:task_results).and_return(domain) expect(MiqTask).to receive(:generic_action_with_callback).with(task_options, queue_options).and_return(task.id) expect(domain).to receive(:update_attribute).with(:enabled, true) - subject.import(git_repo.id, ref_name, 321) end end @@ -99,7 +99,7 @@ context "when import fails and the task result is nil" do let(:git_branches) { [double("GitBranch", :name => ref_name)] } - it "raises an exception with a message" do + it "raises an exception with a message about invalid domain" do allow(task).to receive(:task_results).and_return(nil) expect(MiqTask).to receive(:generic_action_with_callback).with(task_options, queue_options).and_return(task.id) @@ -107,6 +107,16 @@ MiqException::Error, "Selected branch or tag does not contain a valid domain" ) end + + it "raises an exception with a message about multiple domains" do + allow(task).to receive(:task_results).and_return(nil) + allow(task).to receive(:message).and_return('multiple domains') + expect(MiqTask).to receive(:generic_action_with_callback).with(task_options, queue_options).and_return(task.id) + + expect { subject.import(git_repo.id, ref_name, 321) }.to raise_exception( + MiqException::Error, 'Selected branch or tag contains more than one domain' + ) + end end end @@ -115,6 +125,7 @@ before do allow(GitRepository).to receive(:find_by).with(:id => git_repo.id).and_return(git_repo) allow(User).to receive(:current_user).and_return(user) + allow(task).to receive(:message).and_return(nil) end context "when git branches that match the given name exist" do @@ -144,6 +155,7 @@ include_context "import setup" before do allow(User).to receive(:current_user).and_return(user) + allow(task).to receive(:message).and_return(nil) end context "when git branches that match the given name do not exist" do