diff options
author | Stan Hu <stanhu@gmail.com> | 2018-06-05 22:34:06 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-06-06 01:40:55 -0700 |
commit | 3a722ff53fe86ce6194f81ade810196f4f8e870c (patch) | |
tree | 86e7e1b0f8ff5baf148f8f3d03314f942ed0465d /spec/support/controllers | |
parent | af07c490b2a32ed4c88e387d1133e7882f79abc5 (diff) | |
download | gitlab-ce-3a722ff53fe86ce6194f81ade810196f4f8e870c.tar.gz |
Show a more helpful error for import status
Importing a project from GitHub for a project namespace that already exists
would show an unhelpful error, "An error occurred while importing project."
We now add the base message from Projects::CreateService when this fails.
Closes #47365
Diffstat (limited to 'spec/support/controllers')
-rw-r--r-- | spec/support/controllers/githubish_import_controller_shared_examples.rb | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/spec/support/controllers/githubish_import_controller_shared_examples.rb b/spec/support/controllers/githubish_import_controller_shared_examples.rb index 368439aa5b0..1a53c5fa487 100644 --- a/spec/support/controllers/githubish_import_controller_shared_examples.rb +++ b/spec/support/controllers/githubish_import_controller_shared_examples.rb @@ -118,14 +118,34 @@ shared_examples 'a GitHub-ish import controller: POST create' do expect(response).to have_gitlab_http_status(200) end - it 'returns 422 response when the project could not be imported' do + it 'returns 422 response with the base error when the project could not be imported' do + project = build(:project) + error_message = 'This is an error' + project.errors.add(:base, error_message) + + allow(Gitlab::LegacyGithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) + .and_return(double(execute: project)) + + post :create, format: :json + + expect(response).to have_gitlab_http_status(422) + expect(json_response['errors']).to eq(error_message) + end + + it 'returns 422 response with a combined error when the project could not be imported' do + project = build(:project) + project.errors.add(:name, 'is invalid') + project.errors.add(:path, 'is old') + allow(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: build(:project))) + .and_return(double(execute: project)) post :create, format: :json expect(response).to have_gitlab_http_status(422) + expect(json_response['errors']).to eq('Name is invalid, Path is old') end context "when the repository owner is the provider user" do |