Commit e8913e13 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'vij-fix-update-bug' into 'master'

Fix bug with snippet updating error losing changes

See merge request gitlab-org/gitlab!31873
parents 4e8424bf f12f742f
......@@ -48,10 +48,12 @@ module Snippets
true
rescue => e
# Restore old attributes
# Restore old attributes but re-assign changes so they're not lost
unless snippet.previous_changes.empty?
snippet.previous_changes.each { |attr, value| snippet[attr] = value[0] }
snippet.save
snippet.assign_attributes(params)
end
add_snippet_repository_error(snippet: snippet, error: e)
......
---
title: Fix Snippet update error bug losing changes
merge_request: 31873
author:
type: fixed
......@@ -196,14 +196,24 @@ describe Snippets::UpdateService do
end
end
context 'with snippet modifications' do
let(:option_keys) { options.stringify_keys.keys }
it 'rolls back any snippet modifications' do
option_keys = options.stringify_keys.keys
orig_attrs = snippet.attributes.select { |k, v| k.in?(option_keys) }
subject
current_attrs = snippet.attributes.select { |k, v| k.in?(option_keys) }
expect(orig_attrs).to eq current_attrs
persisted_attrs = snippet.reload.attributes.select { |k, v| k.in?(option_keys) }
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
......
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