Commit 81f42274 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'vij-snippets-missing-param-requirement' into 'master'

Allow Snippet description to be individually updated

See merge request gitlab-org/gitlab!41581
parents 512ffad9 78b5fd99
---
title: Add ability to update only Snippet descriptions via REST endpoint
merge_request: 41581
author:
type: changed
......@@ -41,6 +41,10 @@ module API
mutually_exclusive :files, :file_name
end
params :minimum_update_params do
at_least_one_of :content, :description, :files, :file_name, :title, :visibility
end
def content_for(snippet)
if snippet.empty_repo?
env['api.format'] = :txt
......
......@@ -93,8 +93,7 @@ module API
desc: 'The visibility of the snippet'
use :update_file_params
at_least_one_of :title, :file_name, :content, :files, :visibility
use :minimum_update_params
end
# rubocop: disable CodeReuse/ActiveRecord
put ":id/snippets/:snippet_id" do
......
......@@ -106,8 +106,7 @@ module API
desc: 'The visibility of the snippet'
use :update_file_params
at_least_one_of :title, :file_name, :content, :files, :visibility
use :minimum_update_params
end
put ':id' do
snippet = snippets_for_current_user.find_by_id(params.delete(:id))
......
......@@ -306,15 +306,9 @@ RSpec.describe API::ProjectSnippets do
it_behaves_like 'snippet file updates'
it_behaves_like 'snippet non-file updates'
it_behaves_like 'snippet individual non-file updates'
it_behaves_like 'invalid snippet updates'
it 'updates snippet with visibility parameter' do
expect { update_snippet(params: { visibility: 'private' }) }
.to change { snippet.reload.visibility }
expect(snippet.visibility).to eq('private')
end
it_behaves_like 'update with repository actions' do
let(:snippet_without_repo) { create(:project_snippet, author: admin, project: project, visibility_level: visibility_level) }
end
......
......@@ -393,6 +393,7 @@ RSpec.describe API::Snippets do
it_behaves_like 'snippet file updates'
it_behaves_like 'snippet non-file updates'
it_behaves_like 'snippet individual non-file updates'
it_behaves_like 'invalid snippet updates'
it "returns 404 for another user's snippet" do
......
......@@ -170,6 +170,25 @@ RSpec.shared_examples 'snippet non-file updates' do
end
end
RSpec.shared_examples 'snippet individual non-file updates' do
using RSpec::Parameterized::TableSyntax
where(:attribute, :updated_value) do
:description | 'new description'
:title | 'new title'
:visibility | 'private'
end
with_them do
it 'updates the attribute' do
params = { attribute => updated_value }
expect { update_snippet(params: params) }
.to change { snippet.reload.send(attribute) }.to(updated_value)
end
end
end
RSpec.shared_examples 'invalid snippet updates' do
it 'returns 404 for invalid snippet id' do
update_snippet(snippet_id: non_existing_record_id, params: { title: 'foo' })
......
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