Improve error messages when a record is unable to be created for a project
This commit is contained in:
parent
7d7dfee48b
commit
460fb1faba
2 changed files with 17 additions and 0 deletions
|
@ -58,6 +58,9 @@ module Projects
|
||||||
fail(error: @project.errors.full_messages.join(', '))
|
fail(error: @project.errors.full_messages.join(', '))
|
||||||
end
|
end
|
||||||
@project
|
@project
|
||||||
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
|
message = "Unable to save #{e.record.type}: #{e.record.errors.full_messages.join(", ")} "
|
||||||
|
fail(error: message)
|
||||||
rescue => e
|
rescue => e
|
||||||
fail(error: e.message)
|
fail(error: e.message)
|
||||||
end
|
end
|
||||||
|
|
|
@ -144,6 +144,20 @@ describe Projects::CreateService, '#execute', services: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when a bad service template is created' do
|
||||||
|
before do
|
||||||
|
create(:service, type: 'DroneCiService', project: nil, template: true, active: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'reports an error in the imported project' do
|
||||||
|
opts[:import_url] = 'http://www.gitlab.com/gitlab-org/gitlab-ce'
|
||||||
|
project = create_project(user, opts)
|
||||||
|
|
||||||
|
expect(project.errors.full_messages_for(:base).first).to match /Unable to save project. Error: Unable to save DroneCiService/
|
||||||
|
expect(project.services.count).to eq 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_project(user, opts)
|
def create_project(user, opts)
|
||||||
Projects::CreateService.new(user, opts).execute
|
Projects::CreateService.new(user, opts).execute
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue