Avoid updating snippet content when not present

parent cd4e4045
...@@ -38,7 +38,8 @@ module Snippets ...@@ -38,7 +38,8 @@ module Snippets
# Once we can perform different operations through this service # Once we can perform different operations through this service
# we won't need to keep track of the `content` and `file_name` fields # we won't need to keep track of the `content` and `file_name` fields
if snippet_files.any? if snippet_files.any?
params.merge!(content: snippet_files[0].content, file_name: snippet_files[0].file_path) params[:content] = snippet_files[0].content if snippet_files[0].content
params[:file_name] = snippet_files[0].file_path
end end
snippet.assign_attributes(params) snippet.assign_attributes(params)
......
---
title: Avoid updating snippet content when snippet_files content is not present
merge_request: 34865
author:
type: fixed
...@@ -349,6 +349,18 @@ describe Snippets::UpdateService do ...@@ -349,6 +349,18 @@ describe Snippets::UpdateService do
end end
end end
context 'when snippet_file content is not present' do
let(:snippet_files) { [{ action: :move, previous_path: file_path, file_path: 'new_file_path' }] }
it 'does not update snippet content' do
content = snippet.content
expect(subject).to be_success
expect(snippet.reload.content).to eq content
end
end
context 'when snippet_files param is invalid' do context 'when snippet_files param is invalid' do
let(:snippet_files) { [{ action: 'invalid_action' }] } let(:snippet_files) { [{ action: 'invalid_action' }] }
......
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