diff options
author | Stan Hu <stanhu@gmail.com> | 2018-06-06 01:56:50 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-06-06 02:00:49 -0700 |
commit | 332275b766283ff65d0637ada3e4080c3cd4f038 (patch) | |
tree | 25ddd96287f3ea8eb26db54ea1d047acfa2a75ca | |
parent | 3a722ff53fe86ce6194f81ade810196f4f8e870c (diff) | |
download | gitlab-ce-332275b766283ff65d0637ada3e4080c3cd4f038.tar.gz |
Simplify error message handling in Projects::CreateService
There's no need to add a redundant message to the errors if the
model is invalid. This cleans up the message as well for the importer.
-rw-r--r-- | app/controllers/import/base_controller.rb | 7 | ||||
-rw-r--r-- | app/services/projects/create_service.rb | 2 | ||||
-rw-r--r-- | spec/support/controllers/githubish_import_controller_shared_examples.rb | 15 |
3 files changed, 2 insertions, 22 deletions
diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb index 0f401f77fcd..5766c6924cd 100644 --- a/app/controllers/import/base_controller.rb +++ b/app/controllers/import/base_controller.rb @@ -27,11 +27,6 @@ class Import::BaseController < ApplicationController end def project_save_error(project) - # Projects::CreateService will set base message if unable to save - if project.errors[:base].present? - project.errors[:base].last - else - project.errors.full_messages.join(', ') - end + project.errors.full_messages.join(', ') end end diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index d16ecdb7b9b..d4a5b979f63 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -63,6 +63,7 @@ module Projects message = "Unable to save #{e.record.type}: #{e.record.errors.full_messages.join(", ")} " fail(error: message) rescue => e + @project.errors.add(:base, e.message) if @project fail(error: e.message) end @@ -141,7 +142,6 @@ module Projects Rails.logger.error(log_message) if @project - @project.errors.add(:base, message) @project.mark_import_as_failed(message) if @project.persisted? && @project.import? end diff --git a/spec/support/controllers/githubish_import_controller_shared_examples.rb b/spec/support/controllers/githubish_import_controller_shared_examples.rb index 1a53c5fa487..1c1b68c12a2 100644 --- a/spec/support/controllers/githubish_import_controller_shared_examples.rb +++ b/spec/support/controllers/githubish_import_controller_shared_examples.rb @@ -120,21 +120,6 @@ shared_examples 'a GitHub-ish import controller: POST create' 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') |