2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Ci::TriggerPolicy do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:trigger) { create(:ci_trigger, project: project, owner: owner) }
|
|
|
|
|
|
|
|
let(:policies) do
|
2017-09-10 17:25:29 +05:30
|
|
|
described_class.new(user, trigger)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'allows to admin and manage trigger' do
|
|
|
|
it 'does include ability to admin trigger' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(policies).to be_allowed :admin_trigger
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does include ability to manage trigger' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(policies).to be_allowed :manage_trigger
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'allows to manage trigger' do
|
|
|
|
it 'does not include ability to admin trigger' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(policies).not_to be_allowed :admin_trigger
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does include ability to manage trigger' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(policies).to be_allowed :manage_trigger
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'disallows to admin and manage trigger' do
|
|
|
|
it 'does not include ability to admin trigger' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(policies).not_to be_allowed :admin_trigger
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include ability to manage trigger' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(policies).not_to be_allowed :manage_trigger
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#rules' do
|
|
|
|
context 'when owner is undefined' do
|
|
|
|
let(:owner) { nil }
|
|
|
|
|
|
|
|
context 'when user is master of the project' do
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'allows to admin and manage trigger'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer of the project' do
|
|
|
|
before do
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'disallows to admin and manage trigger'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not member of the project' do
|
|
|
|
it_behaves_like 'disallows to admin and manage trigger'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when owner is an user' do
|
|
|
|
let(:owner) { user }
|
|
|
|
|
|
|
|
context 'when user is master of the project' do
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'allows to admin and manage trigger'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when owner is another user' do
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
|
|
|
|
context 'when user is master of the project' do
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'allows to manage trigger'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer of the project' do
|
|
|
|
before do
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'disallows to admin and manage trigger'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not member of the project' do
|
|
|
|
it_behaves_like 'disallows to admin and manage trigger'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|