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
636e8fc4
Commit
636e8fc4
authored
Mar 05, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show git error message updating snippet
parent
67502abd
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
56 additions
and
10 deletions
+56
-10
app/controllers/concerns/snippets_actions.rb
app/controllers/concerns/snippets_actions.rb
+7
-0
app/controllers/projects/snippets_controller.rb
app/controllers/projects/snippets_controller.rb
+1
-1
app/controllers/snippets_controller.rb
app/controllers/snippets_controller.rb
+1
-1
app/services/snippets/update_service.rb
app/services/snippets/update_service.rb
+1
-1
changelogs/unreleased/fj-fix-git-error-message-update-snippet.yml
...gs/unreleased/fj-fix-git-error-message-update-snippet.yml
+5
-0
spec/features/projects/snippets/user_updates_snippet_spec.rb
spec/features/projects/snippets/user_updates_snippet_spec.rb
+21
-4
spec/features/snippets/user_edits_snippet_spec.rb
spec/features/snippets/user_edits_snippet_spec.rb
+18
-1
spec/services/snippets/update_service_spec.rb
spec/services/snippets/update_service_spec.rb
+2
-2
No files found.
app/controllers/concerns/snippets_actions.rb
View file @
636e8fc4
...
...
@@ -28,4 +28,11 @@ module SnippetsActions
def
convert_line_endings
(
content
)
params
[
:line_ending
]
==
'raw'
?
content
:
content
.
gsub
(
/\r\n/
,
"
\n
"
)
end
def
check_repository_error
repository_error
=
snippet
.
errors
.
delete
(
:repository
)
flash
.
now
[
:alert
]
=
repository_error
if
repository_error
recaptcha_check_with_fallback
(
repository_error
.
nil?
)
{
render
:edit
}
end
end
app/controllers/projects/snippets_controller.rb
View file @
636e8fc4
...
...
@@ -62,7 +62,7 @@ class Projects::SnippetsController < Projects::ApplicationController
service_response
=
Snippets
::
UpdateService
.
new
(
project
,
current_user
,
update_params
).
execute
(
@snippet
)
@snippet
=
service_response
.
payload
[
:snippet
]
recaptcha_check_with_fallback
{
render
:edit
}
check_repository_error
end
def
show
...
...
app/controllers/snippets_controller.rb
View file @
636e8fc4
...
...
@@ -64,7 +64,7 @@ class SnippetsController < ApplicationController
service_response
=
Snippets
::
UpdateService
.
new
(
nil
,
current_user
,
update_params
).
execute
(
@snippet
)
@snippet
=
service_response
.
payload
[
:snippet
]
recaptcha_check_with_fallback
{
render
:edit
}
check_repository_error
end
def
show
...
...
app/services/snippets/update_service.rb
View file @
636e8fc4
...
...
@@ -52,7 +52,7 @@ module Snippets
create_commit
(
snippet
)
if
snippet
.
repository_exists?
end
rescue
snippet
.
errors
.
add
(
:
base
,
'Error updating the snippet'
)
snippet
.
errors
.
add
(
:
repository
,
'Error updating the snippet'
)
false
end
...
...
changelogs/unreleased/fj-fix-git-error-message-update-snippet.yml
0 → 100644
View file @
636e8fc4
---
title
:
Show git error message updating snippet
merge_request
:
26570
author
:
type
:
fixed
spec/features/projects/snippets/user_updates_snippet_spec.rb
View file @
636e8fc4
...
...
@@ -3,9 +3,9 @@
require
'spec_helper'
describe
'Projects > Snippets > User updates a snippet'
do
let
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:snippet
)
{
create
(
:project_snippet
,
project:
project
,
author:
user
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
stub_feature_flags
(
snippets_vue:
false
)
...
...
@@ -13,16 +13,33 @@ describe 'Projects > Snippets > User updates a snippet' do
sign_in
(
user
)
visit
(
project_snippet_path
(
project
,
snippet
))
end
it
'updates a snippet'
do
page
.
within
(
'.detail-page-header'
)
do
first
(
:link
,
'Edit'
).
click
end
end
it
'updates a snippet'
do
fill_in
(
'project_snippet_title'
,
with:
'Snippet new title'
)
click_button
(
'Save'
)
expect
(
page
).
to
have_content
(
'Snippet new title'
)
end
context
'when the git operation fails'
do
before
do
allow_next_instance_of
(
Snippets
::
UpdateService
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:create_commit
).
and_raise
(
StandardError
)
end
fill_in
(
'project_snippet_title'
,
with:
'Snippet new title'
)
click_button
(
'Save'
)
end
it
'renders edit page and displays the error'
do
expect
(
page
).
to
have_content
(
'Error updating the snippet'
)
expect
(
page
).
to
have_content
(
'Edit Snippet'
)
end
end
end
spec/features/snippets/user_edits_snippet_spec.rb
View file @
636e8fc4
...
...
@@ -8,7 +8,7 @@ describe 'User edits snippet', :js do
let
(
:file_name
)
{
'test.rb'
}
let
(
:content
)
{
'puts "test"'
}
let
(
:user
)
{
create
(
:user
)
}
let
_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:snippet
)
{
create
(
:personal_snippet
,
:public
,
file_name:
file_name
,
content:
content
,
author:
user
)
}
before
do
...
...
@@ -58,4 +58,21 @@ describe 'User edits snippet', :js do
expect
(
page
).
to
have_no_xpath
(
"//i[@class='fa fa-lock']"
)
expect
(
page
).
to
have_xpath
(
"//i[@class='fa fa-globe']"
)
end
context
'when the git operation fails'
do
before
do
allow_next_instance_of
(
Snippets
::
UpdateService
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:create_commit
).
and_raise
(
StandardError
)
end
fill_in
'personal_snippet_title'
,
with:
'New Snippet Title'
click_button
(
'Save changes'
)
end
it
'renders edit page and displays the error'
do
expect
(
page
).
to
have_content
(
'Error updating the snippet'
)
expect
(
page
).
to
have_content
(
'Edit Snippet'
)
end
end
end
spec/services/snippets/update_service_spec.rb
View file @
636e8fc4
...
...
@@ -148,7 +148,7 @@ describe Snippets::UpdateService do
response
=
subject
expect
(
response
).
to
be_error
expect
(
response
.
payload
[
:snippet
].
errors
.
full_messages
).
to
eq
[
'Error updating the snippet'
]
expect
(
response
.
payload
[
:snippet
].
errors
.
full_messages
).
to
eq
[
'
Repository
Error updating the snippet'
]
end
end
...
...
@@ -173,7 +173,7 @@ describe Snippets::UpdateService do
response
=
subject
expect
(
response
).
to
be_error
expect
(
response
.
payload
[
:snippet
].
errors
.
full_messages
).
to
eq
[
'Error updating the snippet'
]
expect
(
response
.
payload
[
:snippet
].
errors
.
full_messages
).
to
eq
[
'
Repository
Error updating the snippet'
]
end
it
'returns error if snippet does not have a snippet_repository'
do
...
...
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