2019-03-05 02:19:19 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-04 13:37:08 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe CommitPolicy do
|
2019-03-04 13:37:08 -05:00
|
|
|
describe '#rules' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:commit) { project.repository.head_commit }
|
|
|
|
let(:policy) { described_class.new(user, commit) }
|
|
|
|
|
2019-10-29 11:58:26 -04:00
|
|
|
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
|
|
|
|
it 'can not read commit' do
|
|
|
|
expect(policy).to be_disallowed(:read_commit)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can not create a note' do
|
|
|
|
expect(policy).to be_disallowed(:create_note)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-04 13:37:08 -05:00
|
|
|
context 'when project is public' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
|
2019-10-29 11:58:26 -04:00
|
|
|
it_behaves_like 'can read commit and create a note'
|
2019-03-04 13:37:08 -05:00
|
|
|
|
|
|
|
context 'when repository access level is private' do
|
|
|
|
let(:project) { create(:project, :public, :repository, :repository_private) }
|
|
|
|
|
2019-10-29 11:58:26 -04:00
|
|
|
it_behaves_like 'cannot read commit nor create a note'
|
2019-03-04 13:37:08 -05:00
|
|
|
|
|
|
|
context 'when the user is a project member' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
2019-10-29 11:58:26 -04:00
|
|
|
it_behaves_like 'can read commit and create a note'
|
2019-03-04 13:37:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project is private' do
|
|
|
|
let(:project) { create(:project, :private, :repository) }
|
|
|
|
|
2019-10-29 11:58:26 -04:00
|
|
|
it_behaves_like 'cannot read commit nor create a note'
|
2019-03-04 13:37:08 -05:00
|
|
|
|
|
|
|
context 'when the user is a project member' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can read commit and create a note' do
|
|
|
|
expect(policy).to be_allowed(:read_commit)
|
|
|
|
end
|
|
|
|
end
|
2019-10-29 11:58:26 -04:00
|
|
|
|
|
|
|
context 'when 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
|
|
|
|
end
|
2019-03-04 13:37:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|