Commit 263f4247 authored by fjsanpedro's avatar fjsanpedro

Improve requests/api/project_snippets_spec performance

parent 934bbceb
This diff is collapsed.
...@@ -132,7 +132,7 @@ RSpec.describe API::Snippets, factory_default: :keep do ...@@ -132,7 +132,7 @@ RSpec.describe API::Snippets, factory_default: :keep do
end end
describe 'GET /snippets/:id/files/:ref/:file_path/raw' do describe 'GET /snippets/:id/files/:ref/:file_path/raw' do
let(:snippet) { private_snippet } let_it_be(:snippet) { private_snippet }
it_behaves_like 'raw snippet files' do it_behaves_like 'raw snippet files' do
let(:api_path) { "/snippets/#{snippet_id}/files/#{ref}/#{file_path}/raw" } let(:api_path) { "/snippets/#{snippet_id}/files/#{ref}/#{file_path}/raw" }
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'raw snippet files' do RSpec.shared_examples 'raw snippet files' do
let_it_be(:unauthorized_user) { create(:user) } let_it_be(:user_token) { create(:personal_access_token, user: snippet.author) }
let(:snippet_id) { snippet.id } let(:snippet_id) { snippet.id }
let(:user) { snippet.author } let(:user) { snippet.author }
let(:file_path) { '%2Egitattributes' } let(:file_path) { '%2Egitattributes' }
let(:ref) { 'master' } let(:ref) { 'master' }
subject { get api(api_path, personal_access_token: user_token) }
context 'with an invalid snippet ID' do context 'with an invalid snippet ID' do
let(:snippet_id) { 'invalid' } let(:snippet_id) { non_existing_record_id }
it 'returns 404' do it 'returns 404' do
get api(api_path, user) subject
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Snippet Not Found') expect(json_response['message']).to eq('404 Snippet Not Found')
...@@ -22,7 +24,7 @@ RSpec.shared_examples 'raw snippet files' do ...@@ -22,7 +24,7 @@ RSpec.shared_examples 'raw snippet files' do
it 'returns the raw file info' do it 'returns the raw file info' do
expect(Gitlab::Workhorse).to receive(:send_git_blob).and_call_original expect(Gitlab::Workhorse).to receive(:send_git_blob).and_call_original
get api(api_path, user) subject
aggregate_failures do aggregate_failures do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
...@@ -34,6 +36,17 @@ RSpec.shared_examples 'raw snippet files' do ...@@ -34,6 +36,17 @@ RSpec.shared_examples 'raw snippet files' do
end end
end end
context 'with unauthorized user' do
let(:user_token) { create(:personal_access_token) }
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Snippet Not Found')
end
end
context 'with invalid params' do context 'with invalid params' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
...@@ -50,12 +63,12 @@ RSpec.shared_examples 'raw snippet files' do ...@@ -50,12 +63,12 @@ RSpec.shared_examples 'raw snippet files' do
end end
with_them do with_them do
before do it 'returns the proper response code and message' do
get api(api_path, user) subject
end
it { expect(response).to have_gitlab_http_status(status) } expect(response).to have_gitlab_http_status(status)
it { expect(json_response[key]).to eq(message) } expect(json_response[key]).to eq(message)
end
end end
end end
end end
...@@ -256,7 +269,7 @@ end ...@@ -256,7 +269,7 @@ end
RSpec.shared_examples 'expected response status' do RSpec.shared_examples 'expected response status' do
it 'returns the correct response' do it 'returns the correct response' do
get api(path, user) get api(path, personal_access_token: user_token)
expect(response).to have_gitlab_http_status(status) expect(response).to have_gitlab_http_status(status)
end end
...@@ -265,7 +278,7 @@ end ...@@ -265,7 +278,7 @@ end
RSpec.shared_examples 'unauthenticated project snippet access' do RSpec.shared_examples 'unauthenticated project snippet access' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
let(:user) { nil } let(:user_token) { nil }
where(:project_visibility, :snippet_visibility, :status) do where(:project_visibility, :snippet_visibility, :status) do
:public | :public | :ok :public | :public | :ok
...@@ -317,6 +330,8 @@ RSpec.shared_examples 'member project snippet access' do ...@@ -317,6 +330,8 @@ RSpec.shared_examples 'member project snippet access' do
end end
RSpec.shared_examples 'project snippet access levels' do RSpec.shared_examples 'project snippet access levels' do
let_it_be(:user_token) { create(:personal_access_token, user: user) }
let(:project) { create(:project, project_visibility) } let(:project) { create(:project, project_visibility) }
let(:snippet) { create(:project_snippet, :repository, snippet_visibility, project: project) } let(:snippet) { create(:project_snippet, :repository, snippet_visibility, project: project) }
......
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