Commit 3c3ce8d7 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '228706-fj-improve-api-project-snippet-spec' into 'master'

Improve requests/api/project_snippets_spec performance

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