1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::Snippets::BlobsController do
using RSpec::Parameterized::TableSyntax
include SnippetHelpers
let_it_be(:author) { create(:user) }
let_it_be(:developer) { create(:user) }
let_it_be(:other_user) { create(:user) }
let(:visibility) { :public }
let(:project_visibility) { :public }
let(:project) { create(:project, project_visibility) }
let(:snippet) { create(:project_snippet, visibility, :repository, project: project, author: author) }
before do
project.add_maintainer(author)
project.add_developer(developer)
end
describe 'GET #raw' do
let(:filepath) { 'file1' }
let(:ref) { TestEnv::BRANCH_SHA['snippet/single-file'] }
let(:inline) { nil }
subject do
get :raw, params: {
namespace_id: project.namespace,
project_id: project,
snippet_id: snippet,
path: filepath,
ref: ref,
inline: inline
}
end
context 'with a snippet without a repository' do
let(:snippet) { create(:project_snippet, visibility, project: project, author: author) }
it_behaves_like 'raw snippet without repository', :not_found
end
where(:project_visibility_level, :snippet_visibility_level, :user, :status) do
:public | :public | :author | :ok
:public | :public | :developer | :ok
:public | :public | :other_user | :ok
:public | :public | nil | :ok
:public | :private | :author | :ok
:public | :private | :developer | :ok
:public | :private | :other_user | :not_found
:public | :private | nil | :not_found
:private | :public | :author | :ok
:private | :public | :developer | :ok
:private | :public | :other_user | :not_found
:private | :public | nil | :redirect
:private | :private | :author | :ok
:private | :private | :developer | :ok
:private | :private | :other_user | :not_found
:private | :private | nil | :redirect
end
with_them do
let(:visibility) { snippet_visibility_level }
let(:project_visibility) { project_visibility_level }
before do
sign_in_as(user)
subject
end
it 'responds with correct status' do
expect(response).to have_gitlab_http_status(status)
end
end
it_behaves_like 'raw snippet blob'
end
end
|