Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a95cb202
Commit
a95cb202
authored
Apr 01, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show snippet error update to the user
parent
964f191d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
10 deletions
+23
-10
app/services/snippets/update_service.rb
app/services/snippets/update_service.rb
+1
-1
changelogs/unreleased/fj-show-error-message-snippet-update.yml
...elogs/unreleased/fj-show-error-message-snippet-update.yml
+5
-0
spec/features/projects/snippets/user_updates_snippet_spec.rb
spec/features/projects/snippets/user_updates_snippet_spec.rb
+4
-2
spec/features/snippets/user_edits_snippet_spec.rb
spec/features/snippets/user_edits_snippet_spec.rb
+4
-2
spec/services/snippets/update_service_spec.rb
spec/services/snippets/update_service_spec.rb
+9
-5
No files found.
app/services/snippets/update_service.rb
View file @
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
...
...
changelogs/unreleased/fj-show-error-message-snippet-update.yml
0 → 100644
View file @
a95cb202
---
title
:
Show snippet error update to the user
merge_request
:
28516
author
:
type
:
changed
spec/features/projects/snippets/user_updates_snippet_spec.rb
View file @
a95cb202
...
...
@@ -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
...
...
spec/features/snippets/user_edits_snippet_spec.rb
View file @
a95cb202
...
...
@@ -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
...
...
spec/services/snippets/update_service_spec.rb
View file @
a95cb202
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment