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
f12f742f
Commit
f12f742f
authored
May 13, 2020
by
Vijay Hawoldar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug with snippet updating error losing changes
parent
4907a8d6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
7 deletions
+24
-7
app/services/snippets/update_service.rb
app/services/snippets/update_service.rb
+3
-1
changelogs/unreleased/vij-fix-update-bug.yml
changelogs/unreleased/vij-fix-update-bug.yml
+5
-0
spec/services/snippets/update_service_spec.rb
spec/services/snippets/update_service_spec.rb
+16
-6
No files found.
app/services/snippets/update_service.rb
View file @
f12f742f
...
@@ -48,10 +48,12 @@ module Snippets
...
@@ -48,10 +48,12 @@ module Snippets
true
true
rescue
=>
e
rescue
=>
e
# Restore old attributes
# Restore old attributes
but re-assign changes so they're not lost
unless
snippet
.
previous_changes
.
empty?
unless
snippet
.
previous_changes
.
empty?
snippet
.
previous_changes
.
each
{
|
attr
,
value
|
snippet
[
attr
]
=
value
[
0
]
}
snippet
.
previous_changes
.
each
{
|
attr
,
value
|
snippet
[
attr
]
=
value
[
0
]
}
snippet
.
save
snippet
.
save
snippet
.
assign_attributes
(
params
)
end
end
snippet
.
errors
.
add
(
:repository
,
'Error updating the snippet'
)
snippet
.
errors
.
add
(
:repository
,
'Error updating the snippet'
)
...
...
changelogs/unreleased/vij-fix-update-bug.yml
0 → 100644
View file @
f12f742f
---
title
:
Fix Snippet update error bug losing changes
merge_request
:
31873
author
:
type
:
fixed
spec/services/snippets/update_service_spec.rb
View file @
f12f742f
...
@@ -196,14 +196,24 @@ describe Snippets::UpdateService do
...
@@ -196,14 +196,24 @@ describe Snippets::UpdateService do
end
end
end
end
context
'with snippet modifications'
do
let
(
:option_keys
)
{
options
.
stringify_keys
.
keys
}
it
'rolls back any snippet modifications'
do
it
'rolls back any snippet modifications'
do
option_keys
=
options
.
stringify_keys
.
keys
orig_attrs
=
snippet
.
attributes
.
select
{
|
k
,
v
|
k
.
in?
(
option_keys
)
}
orig_attrs
=
snippet
.
attributes
.
select
{
|
k
,
v
|
k
.
in?
(
option_keys
)
}
subject
subject
current_attrs
=
snippet
.
attributes
.
select
{
|
k
,
v
|
k
.
in?
(
option_keys
)
}
persisted_attrs
=
snippet
.
reload
.
attributes
.
select
{
|
k
,
v
|
k
.
in?
(
option_keys
)
}
expect
(
orig_attrs
).
to
eq
current_attrs
expect
(
orig_attrs
).
to
eq
persisted_attrs
end
it
'keeps any snippet modifications'
do
subject
instance_attrs
=
snippet
.
attributes
.
select
{
|
k
,
v
|
k
.
in?
(
option_keys
)
}
expect
(
options
.
stringify_keys
).
to
eq
instance_attrs
end
end
end
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