Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-04 18:08:09 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-04 18:08:09 +0300
commitd3fc3be040a4fed2328e23ef28696dd8bd8238b4 (patch)
treef1874ea5e6e3c50c6a3c2ca2900af4ae73a53119 /spec/requests/api
parentc6c7437861bff9572747674095c4dfbdfbea4988 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/api')
-rw-r--r--spec/requests/api/graphql/mutations/snippets/update_spec.rb4
-rw-r--r--spec/requests/api/project_snippets_spec.rb36
-rw-r--r--spec/requests/api/snippets_spec.rb32
3 files changed, 40 insertions, 32 deletions
diff --git a/spec/requests/api/graphql/mutations/snippets/update_spec.rb b/spec/requests/api/graphql/mutations/snippets/update_spec.rb
index 820c97e8341..1035e3346e1 100644
--- a/spec/requests/api/graphql/mutations/snippets/update_spec.rb
+++ b/spec/requests/api/graphql/mutations/snippets/update_spec.rb
@@ -91,7 +91,7 @@ describe 'Updating a Snippet' do
describe 'PersonalSnippet' do
it_behaves_like 'graphql update actions' do
- let_it_be(:snippet) do
+ let(:snippet) do
create(:personal_snippet,
:private,
file_name: original_file_name,
@@ -104,7 +104,7 @@ describe 'Updating a Snippet' do
describe 'ProjectSnippet' do
let_it_be(:project) { create(:project, :private) }
- let_it_be(:snippet) do
+ let(:snippet) do
create(:project_snippet,
:private,
project: project,
diff --git a/spec/requests/api/project_snippets_spec.rb b/spec/requests/api/project_snippets_spec.rb
index ba5de430f7d..e018a4643db 100644
--- a/spec/requests/api/project_snippets_spec.rb
+++ b/spec/requests/api/project_snippets_spec.rb
@@ -278,13 +278,13 @@ describe API::ProjectSnippets do
describe 'PUT /projects/:project_id/snippets/:id/' do
let(:visibility_level) { Snippet::PUBLIC }
- let(:snippet) { create(:project_snippet, author: admin, visibility_level: visibility_level, project: project) }
+ let(:snippet) { create(:project_snippet, :repository, author: admin, visibility_level: visibility_level, project: project) }
it 'updates snippet' do
new_content = 'New content'
new_description = 'New description'
- put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin), params: { code: new_content, description: new_description, visibility: 'private' }
+ update_snippet(params: { code: new_content, description: new_description, visibility: 'private' })
expect(response).to have_gitlab_http_status(:ok)
snippet.reload
@@ -297,7 +297,7 @@ describe API::ProjectSnippets 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 }
+ update_snippet(params: { content: new_content, description: new_description })
expect(response).to have_gitlab_http_status(:ok)
snippet.reload
@@ -306,21 +306,21 @@ describe API::ProjectSnippets do
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' }
+ update_snippet(params: { code: 'some content', content: 'other content' })
expect(response).to have_gitlab_http_status(:bad_request)
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' }
+ update_snippet(snippet_id: '1234', params: { title: 'foo' })
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Snippet Not Found')
end
it 'returns 400 for missing parameters' do
- put api("/projects/#{project.id}/snippets/1234", admin)
+ update_snippet
expect(response).to have_gitlab_http_status(:bad_request)
end
@@ -328,16 +328,16 @@ describe API::ProjectSnippets do
it 'returns 400 for empty code field' do
new_content = ''
- put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin), params: { code: new_content }
+ update_snippet(params: { code: new_content })
expect(response).to have_gitlab_http_status(:bad_request)
end
- context 'when the snippet is spam' do
- def update_snippet(snippet_params = {})
- put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}", admin), params: snippet_params
- 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
+ context 'when the snippet is spam' do
before do
allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
@@ -348,7 +348,7 @@ describe API::ProjectSnippets do
let(:visibility_level) { Snippet::PRIVATE }
it 'creates the snippet' do
- expect { update_snippet(title: 'Foo') }
+ expect { update_snippet(params: { title: 'Foo' }) }
.to change { snippet.reload.title }.to('Foo')
end
end
@@ -357,12 +357,12 @@ describe API::ProjectSnippets do
let(:visibility_level) { Snippet::PUBLIC }
it 'rejects the snippet' do
- expect { update_snippet(title: 'Foo') }
+ expect { update_snippet(params: { title: 'Foo' }) }
.not_to change { snippet.reload.title }
end
it 'creates a spam log' do
- expect { update_snippet(title: 'Foo') }
+ expect { update_snippet(params: { title: 'Foo' }) }
.to log_spam(title: 'Foo', user_id: admin.id, noteable_type: 'ProjectSnippet')
end
end
@@ -371,7 +371,7 @@ describe API::ProjectSnippets do
let(:visibility_level) { Snippet::PRIVATE }
it 'rejects the snippet' do
- expect { update_snippet(title: 'Foo', visibility: 'public') }
+ expect { update_snippet(params: { title: 'Foo', visibility: 'public' }) }
.not_to change { snippet.reload.title }
expect(response).to have_gitlab_http_status(:bad_request)
@@ -379,7 +379,7 @@ describe API::ProjectSnippets do
end
it 'creates a spam log' do
- expect { update_snippet(title: 'Foo', visibility: 'public') }
+ expect { update_snippet(params: { title: 'Foo', visibility: 'public' }) }
.to log_spam(title: 'Foo', user_id: admin.id, noteable_type: 'ProjectSnippet')
end
end
@@ -390,6 +390,10 @@ describe API::ProjectSnippets do
let(:request) { put api("/projects/#{project_no_snippets.id}/snippets/123", admin), params: { description: 'foo' } }
end
end
+
+ def update_snippet(snippet_id: snippet.id, params: {})
+ put api("/projects/#{snippet.project.id}/snippets/#{snippet_id}", admin), params: params
+ end
end
describe 'DELETE /projects/:project_id/snippets/:id/' do
diff --git a/spec/requests/api/snippets_spec.rb b/spec/requests/api/snippets_spec.rb
index d399c2b3f1c..627611c10ce 100644
--- a/spec/requests/api/snippets_spec.rb
+++ b/spec/requests/api/snippets_spec.rb
@@ -301,7 +301,7 @@ describe API::Snippets do
let(:visibility_level) { Snippet::PUBLIC }
let(:other_user) { create(:user) }
let(:snippet) do
- create(:personal_snippet, author: user, visibility_level: visibility_level)
+ create(:personal_snippet, :repository, author: user, visibility_level: visibility_level)
end
shared_examples 'snippet updates' do
@@ -309,7 +309,7 @@ describe API::Snippets do
new_content = 'New content'
new_description = 'New description'
- put api("/snippets/#{snippet.id}", user), params: { content: new_content, description: new_description, visibility: 'internal' }
+ update_snippet(params: { content: new_content, description: new_description, visibility: 'internal' })
expect(response).to have_gitlab_http_status(:ok)
snippet.reload
@@ -332,30 +332,30 @@ describe API::Snippets do
it_behaves_like 'snippet updates'
it 'returns 404 for invalid snippet id' do
- put api("/snippets/1234", user), params: { title: 'foo' }
+ update_snippet(snippet_id: '1234', params: { title: 'Foo' })
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Snippet Not Found')
end
it "returns 404 for another user's snippet" do
- put api("/snippets/#{snippet.id}", other_user), params: { title: 'fubar' }
+ update_snippet(requester: other_user, params: { title: 'foobar' })
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Snippet Not Found')
end
it 'returns 400 for missing parameters' do
- put api("/snippets/1234", user)
+ update_snippet
expect(response).to have_gitlab_http_status(:bad_request)
end
- context 'when the snippet is spam' do
- def update_snippet(snippet_params = {})
- put api("/snippets/#{snippet.id}", user), params: snippet_params
- end
+ it_behaves_like 'update with repository actions' do
+ let(:snippet_without_repo) { create(:personal_snippet, author: user, visibility_level: visibility_level) }
+ end
+ context 'when the snippet is spam' do
before do
allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
@@ -366,7 +366,7 @@ describe API::Snippets do
let(:visibility_level) { Snippet::PRIVATE }
it 'updates the snippet' do
- expect { update_snippet(title: 'Foo') }
+ expect { update_snippet(params: { title: 'Foo' }) }
.to change { snippet.reload.title }.to('Foo')
end
end
@@ -375,7 +375,7 @@ describe API::Snippets do
let(:visibility_level) { Snippet::PUBLIC }
it 'rejects the shippet' do
- expect { update_snippet(title: 'Foo') }
+ expect { update_snippet(params: { title: 'Foo' }) }
.not_to change { snippet.reload.title }
expect(response).to have_gitlab_http_status(:bad_request)
@@ -383,7 +383,7 @@ describe API::Snippets do
end
it 'creates a spam log' do
- expect { update_snippet(title: 'Foo') }.to log_spam(title: 'Foo', user_id: user.id, noteable_type: 'PersonalSnippet')
+ expect { update_snippet(params: { title: 'Foo' }) }.to log_spam(title: 'Foo', user_id: user.id, noteable_type: 'PersonalSnippet')
end
end
@@ -391,16 +391,20 @@ describe API::Snippets do
let(:visibility_level) { Snippet::PRIVATE }
it 'rejects the snippet' do
- expect { update_snippet(title: 'Foo', visibility: 'public') }
+ expect { update_snippet(params: { title: 'Foo', visibility: 'public' }) }
.not_to change { snippet.reload.title }
end
it 'creates a spam log' do
- expect { update_snippet(title: 'Foo', visibility: 'public') }
+ expect { update_snippet(params: { title: 'Foo', visibility: 'public' }) }
.to log_spam(title: 'Foo', user_id: user.id, noteable_type: 'PersonalSnippet')
end
end
end
+
+ def update_snippet(snippet_id: snippet.id, params: {}, requester: user)
+ put api("/snippets/#{snippet_id}", requester), params: params
+ end
end
describe 'DELETE /snippets/:id' do