Skip to content

Commit

Permalink
Merge pull request #2899 from pkomanek/ae_git_import_multiple_domains
Browse files Browse the repository at this point in the history
ae_import multiple domains
(cherry picked from commit d4b7f57)
  • Loading branch information
martinpovolny authored and simaishi committed Jan 3, 2018
1 parent 2ee79aa commit 0353aeb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/services/git_based_domain_import_service.rb
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions spec/services/git_based_domain_import_service_spec.rb
Expand Up @@ -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
Expand All @@ -91,22 +92,31 @@
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

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)

expect { subject.import(git_repo.id, ref_name, 321) }.to raise_exception(
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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0353aeb

Please sign in to comment.