2017-03-07 08:02:56 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
describe Ci::TriggerPolicy do
|
2017-03-07 08:02:56 -05:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-03-07 08:02:56 -05:00
|
|
|
let(:trigger) { create(:ci_trigger, project: project, owner: owner) }
|
|
|
|
|
|
|
|
let(:policies) do
|
2017-04-06 17:09:58 -04:00
|
|
|
described_class.new(user, trigger)
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'allows to admin and manage trigger' do
|
|
|
|
it 'does include ability to admin trigger' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(policies).to be_allowed :admin_trigger
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does include ability to manage trigger' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(policies).to be_allowed :manage_trigger
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'allows to manage trigger' do
|
|
|
|
it 'does not include ability to admin trigger' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(policies).not_to be_allowed :admin_trigger
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does include ability to manage trigger' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(policies).to be_allowed :manage_trigger
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'disallows to admin and manage trigger' do
|
|
|
|
it 'does not include ability to admin trigger' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(policies).not_to be_allowed :admin_trigger
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include ability to manage trigger' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(policies).not_to be_allowed :manage_trigger
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#rules' do
|
|
|
|
context 'when owner is undefined' do
|
|
|
|
let(:owner) { nil }
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer of the project' do
|
2017-03-07 08:02:56 -05:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'allows to admin and manage trigger'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer of the project' do
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2017-03-07 08:02:56 -05:00
|
|
|
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 }
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer of the project' do
|
2017-03-07 08:02:56 -05:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'allows to admin and manage trigger'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when owner is another user' do
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer of the project' do
|
2017-03-07 08:02:56 -05:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'allows to manage trigger'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer of the project' do
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2017-03-07 08:02:56 -05:00
|
|
|
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
|