debian-mirror-gitlab/spec/policies/commit_policy_spec.rb

141 lines
3.8 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2019-03-13 22:55:13 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe CommitPolicy do
2019-03-13 22:55:13 +05:30
describe '#rules' do
2022-10-11 01:57:18 +05:30
let(:group) { create(:group, :public) }
2019-03-13 22:55:13 +05:30
let(:user) { create(:user) }
let(:commit) { project.repository.head_commit }
let(:policy) { described_class.new(user, commit) }
2019-10-31 01:37:42 +05:30
shared_examples 'can read commit and create a note' do
it 'can read commit' do
expect(policy).to be_allowed(:read_commit)
end
it 'can create a note' do
expect(policy).to be_allowed(:create_note)
end
end
shared_examples 'cannot read commit nor create a note' do
2022-10-11 01:57:18 +05:30
it 'cannot read commit' do
2019-10-31 01:37:42 +05:30
expect(policy).to be_disallowed(:read_commit)
end
2022-10-11 01:57:18 +05:30
it 'cannot create a note' do
2019-10-31 01:37:42 +05:30
expect(policy).to be_disallowed(:create_note)
end
end
2019-03-13 22:55:13 +05:30
context 'when project is public' do
2022-10-11 01:57:18 +05:30
let(:project) { create(:project, :public, :repository, group: group) }
2019-03-13 22:55:13 +05:30
2022-10-11 01:57:18 +05:30
context 'when the user is not a project member' do
it_behaves_like 'can read commit and create a note'
end
2019-03-13 22:55:13 +05:30
context 'when repository access level is private' do
2022-10-11 01:57:18 +05:30
let(:project) { create(:project, :public, :repository, :repository_private, group: group) }
2019-03-13 22:55:13 +05:30
2022-10-11 01:57:18 +05:30
context 'when the user is not a project member' do
it_behaves_like 'cannot read commit nor create a note'
end
2019-03-13 22:55:13 +05:30
2022-10-11 01:57:18 +05:30
context 'when the user is a direct project member' do
context 'and the user is a developer' do
before do
project.add_developer(user)
end
it_behaves_like 'can read commit and create a note'
2019-03-13 22:55:13 +05:30
end
2022-10-11 01:57:18 +05:30
end
2019-03-13 22:55:13 +05:30
2022-10-11 01:57:18 +05:30
context 'when the user is an inherited member from the group' do
context 'and the user is a guest' do
before do
group.add_guest(user)
end
it_behaves_like 'can read commit and create a note'
end
context 'and the user is a reporter' do
before do
group.add_reporter(user)
end
it_behaves_like 'can read commit and create a note'
end
context 'and the user is a developer' do
before do
group.add_developer(user)
end
it_behaves_like 'can read commit and create a note'
end
2019-03-13 22:55:13 +05:30
end
end
end
context 'when project is private' do
2022-10-11 01:57:18 +05:30
let(:project) { create(:project, :private, :repository, group: group) }
2019-03-13 22:55:13 +05:30
2022-10-11 01:57:18 +05:30
context 'when the user is not a project member' do
it_behaves_like 'cannot read commit nor create a note'
end
2019-03-13 22:55:13 +05:30
2022-10-11 01:57:18 +05:30
context 'when the user is a direct project member' do
context 'and the user is a developer' do
before do
project.add_developer(user)
end
it_behaves_like 'can read commit and create a note'
2019-03-13 22:55:13 +05:30
end
2022-10-11 01:57:18 +05:30
context 'and the user is a guest' do
before do
project.add_guest(user)
end
it_behaves_like 'cannot read commit nor create a note'
it 'cannot download code' do
expect(policy).to be_disallowed(:download_code)
end
2019-03-13 22:55:13 +05:30
end
end
2019-10-31 01:37:42 +05:30
2022-10-11 01:57:18 +05:30
context 'when the user is an inherited member from the group' do
context 'and the user is a guest' do
before do
group.add_guest(user)
end
it_behaves_like 'cannot read commit nor create a note'
2019-10-31 01:37:42 +05:30
end
2022-10-11 01:57:18 +05:30
context 'and the user is a reporter' do
before do
group.add_reporter(user)
end
it_behaves_like 'can read commit and create a note'
end
2019-10-31 01:37:42 +05:30
2022-10-11 01:57:18 +05:30
context 'and the user is a developer' do
before do
group.add_developer(user)
end
it_behaves_like 'can read commit and create a note'
2019-10-31 01:37:42 +05:30
end
end
2019-03-13 22:55:13 +05:30
end
end
end