Commit 981d4236 authored by James Lopez's avatar James Lopez

Merge branch 'fj-show-error-message-snippet-update' into 'master'

Show snippet error update to the user

See merge request gitlab-org/gitlab!28516
parents 7e0d3231 a95cb202
......@@ -52,7 +52,7 @@ module Snippets
create_commit(snippet) if snippet.repository_exists?
end
rescue => e
snippet.errors.add(:repository, 'Error updating the snippet')
snippet.errors.add(:repository, e.message)
log_error(e.message)
false
......
---
title: Show snippet error update to the user
merge_request: 28516
author:
type: changed
......@@ -54,9 +54,11 @@ describe 'Projects > Snippets > User updates a snippet', :js do
end
context 'when the git operation fails' do
let(:error_message) { 'foobar' }
before do
allow_next_instance_of(Snippets::UpdateService) do |instance|
allow(instance).to receive(:create_commit).and_raise(StandardError)
allow(instance).to receive(:create_commit).and_raise(StandardError, error_message)
end
fill_in('project_snippet_title', with: 'Snippet new title')
......@@ -65,7 +67,7 @@ describe 'Projects > Snippets > User updates a snippet', :js do
end
it 'renders edit page and displays the error' do
expect(page.find('.flash-container span').text).to eq('Error updating the snippet')
expect(page.find('.flash-container span').text).to eq(error_message)
expect(page).to have_content('Edit Snippet')
end
end
......
......@@ -85,9 +85,11 @@ describe 'User edits snippet', :js do
end
context 'when the git operation fails' do
let(:error_message) { 'foobar' }
before do
allow_next_instance_of(Snippets::UpdateService) do |instance|
allow(instance).to receive(:create_commit).and_raise(StandardError)
allow(instance).to receive(:create_commit).and_raise(StandardError, error_message)
end
fill_in 'personal_snippet_title', with: 'New Snippet Title'
......@@ -96,7 +98,7 @@ describe 'User edits snippet', :js do
end
it 'renders edit page and displays the error' do
expect(page.find('.flash-container span').text).to eq('Error updating the snippet')
expect(page.find('.flash-container span').text).to eq(error_message)
expect(page).to have_content('Edit Snippet')
end
end
......
......@@ -141,14 +141,16 @@ describe Snippets::UpdateService do
end
it 'returns error when the commit action fails' do
error_message = 'foobar'
allow_next_instance_of(SnippetRepository) do |instance|
allow(instance).to receive(:multi_files_action).and_raise(SnippetRepository::CommitError)
allow(instance).to receive(:multi_files_action).and_raise(SnippetRepository::CommitError, error_message)
end
response = subject
expect(response).to be_error
expect(response.payload[:snippet].errors.full_messages).to eq ['Repository Error updating the snippet']
expect(response.payload[:snippet].errors[:repository].to_sentence).to eq error_message
end
end
......@@ -168,12 +170,14 @@ describe Snippets::UpdateService do
end
context 'when an error is raised' do
let(:error_message) { 'foobar' }
before do
allow(snippet.snippet_repository).to receive(:multi_files_action).and_raise(SnippetRepository::CommitError, 'foobar')
allow(snippet.snippet_repository).to receive(:multi_files_action).and_raise(SnippetRepository::CommitError, error_message)
end
it 'logs the error' do
expect(Gitlab::AppLogger).to receive(:error).with('foobar')
expect(Gitlab::AppLogger).to receive(:error).with(error_message)
subject
end
......@@ -182,7 +186,7 @@ describe Snippets::UpdateService do
response = subject
expect(response).to be_error
expect(response.payload[:snippet].errors.full_messages).to eq ['Repository Error updating the snippet']
expect(response.payload[:snippet].errors[:repository].to_sentence).to eq error_message
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment