diff options
author | Stan Hu <stanhu@gmail.com> | 2019-08-27 22:52:27 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-08-29 08:54:07 +0300 |
commit | fc52421b552dace1a8d1410adc23b7bfddc5a580 (patch) | |
tree | 816c2b226b7a65eccc1acdbd9bd403369fb073ce /spec/requests/api/project_snippets_spec.rb | |
parent | 549e95b8f921dfb30bc7982e9957ce9ccdfd916e (diff) |
Standardize use of `content` parameter in snippets API
There was some confusion over whether `code` or `content` is the right
parameter for snippets. Internally, the database stores
`content`. However:
1. Project snippets use `code`. `code` gets remapped in `content` in
`lib/api/project_snippets.rb`.
2. Personal snippets use `content`.
To unify these APIs, allow an alias of `content` to work for project
snippets.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/66673
Diffstat (limited to 'spec/requests/api/project_snippets_spec.rb')
-rw-r--r-- | spec/requests/api/project_snippets_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/requests/api/project_snippets_spec.rb b/spec/requests/api/project_snippets_spec.rb index 29f69b6ce20..5ee46f7fc31 100644 --- a/spec/requests/api/project_snippets_spec.rb +++ b/spec/requests/api/project_snippets_spec.rb @@ -108,6 +108,29 @@ describe API::ProjectSnippets do expect(snippet.visibility_level).to eq(Snippet::PUBLIC) end + it 'creates a new snippet with content parameter' do + params[:content] = params.delete(:code) + + post api("/projects/#{project.id}/snippets/", admin), params: params + + expect(response).to have_gitlab_http_status(201) + snippet = ProjectSnippet.find(json_response['id']) + expect(snippet.content).to eq(params[:content]) + expect(snippet.description).to eq(params[:description]) + expect(snippet.title).to eq(params[:title]) + expect(snippet.file_name).to eq(params[:file_name]) + expect(snippet.visibility_level).to eq(Snippet::PUBLIC) + end + + it 'returns 400 when both code and content parameters specified' do + params[:content] = params[:code] + + post api("/projects/#{project.id}/snippets/", admin), params: params + + expect(response).to have_gitlab_http_status(400) + expect(json_response['error']).to eq('code, content are mutually exclusive') + end + it 'returns 400 for missing parameters' do params.delete(:title) @@ -175,6 +198,25 @@ describe API::ProjectSnippets do expect(snippet.description).to eq(new_description) end + it 'updates snippet with content parameter' do + new_content = 'New content' + new_description = 'New description' + + put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin), params: { content: new_content, description: new_description } + + expect(response).to have_gitlab_http_status(200) + snippet.reload + expect(snippet.content).to eq(new_content) + expect(snippet.description).to eq(new_description) + end + + it 'returns 400 when both code and content parameters specified' do + put api("/projects/#{snippet.project.id}/snippets/1234", admin), params: { code: 'some content', content: 'other content' } + + expect(response).to have_gitlab_http_status(400) + expect(json_response['error']).to eq('code, content are mutually exclusive') + end + it 'returns 404 for invalid snippet id' do put api("/projects/#{snippet.project.id}/snippets/1234", admin), params: { title: 'foo' } |