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 ...@@ -52,7 +52,7 @@ module Snippets
create_commit(snippet) if snippet.repository_exists? create_commit(snippet) if snippet.repository_exists?
end end
rescue => e rescue => e
snippet.errors.add(:repository, 'Error updating the snippet') snippet.errors.add(:repository, e.message)
log_error(e.message) log_error(e.message)
false 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 ...@@ -54,9 +54,11 @@ describe 'Projects > Snippets > User updates a snippet', :js do
end end
context 'when the git operation fails' do context 'when the git operation fails' do
let(:error_message) { 'foobar' }
before do before do
allow_next_instance_of(Snippets::UpdateService) do |instance| 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 end
fill_in('project_snippet_title', with: 'Snippet new title') fill_in('project_snippet_title', with: 'Snippet new title')
...@@ -65,7 +67,7 @@ describe 'Projects > Snippets > User updates a snippet', :js do ...@@ -65,7 +67,7 @@ describe 'Projects > Snippets > User updates a snippet', :js do
end end
it 'renders edit page and displays the error' do 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') expect(page).to have_content('Edit Snippet')
end end
end end
......
...@@ -85,9 +85,11 @@ describe 'User edits snippet', :js do ...@@ -85,9 +85,11 @@ describe 'User edits snippet', :js do
end end
context 'when the git operation fails' do context 'when the git operation fails' do
let(:error_message) { 'foobar' }
before do before do
allow_next_instance_of(Snippets::UpdateService) do |instance| 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 end
fill_in 'personal_snippet_title', with: 'New Snippet Title' fill_in 'personal_snippet_title', with: 'New Snippet Title'
...@@ -96,7 +98,7 @@ describe 'User edits snippet', :js do ...@@ -96,7 +98,7 @@ describe 'User edits snippet', :js do
end end
it 'renders edit page and displays the error' do 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') expect(page).to have_content('Edit Snippet')
end end
end end
......
...@@ -141,14 +141,16 @@ describe Snippets::UpdateService do ...@@ -141,14 +141,16 @@ describe Snippets::UpdateService do
end end
it 'returns error when the commit action fails' do it 'returns error when the commit action fails' do
error_message = 'foobar'
allow_next_instance_of(SnippetRepository) do |instance| 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 end
response = subject response = subject
expect(response).to be_error 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
end end
...@@ -168,12 +170,14 @@ describe Snippets::UpdateService do ...@@ -168,12 +170,14 @@ describe Snippets::UpdateService do
end end
context 'when an error is raised' do context 'when an error is raised' do
let(:error_message) { 'foobar' }
before do 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 end
it 'logs the error' do it 'logs the error' do
expect(Gitlab::AppLogger).to receive(:error).with('foobar') expect(Gitlab::AppLogger).to receive(:error).with(error_message)
subject subject
end end
...@@ -182,7 +186,7 @@ describe Snippets::UpdateService do ...@@ -182,7 +186,7 @@ describe Snippets::UpdateService do
response = subject response = subject
expect(response).to be_error 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
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