2019-10-24 20:06:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-07 08:02:56 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.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) }
|
2019-06-25 07:41:11 -04:00
|
|
|
let(:trigger) { create(:ci_trigger, project: project, owner: create(:user)) }
|
2017-03-07 08:02:56 -05:00
|
|
|
|
2019-06-25 07:41:11 -04:00
|
|
|
subject { described_class.new(user, trigger) }
|
2017-03-07 08:02:56 -05:00
|
|
|
|
|
|
|
describe '#rules' do
|
|
|
|
context 'when owner is an user' do
|
2019-06-25 07:41:11 -04:00
|
|
|
before do
|
|
|
|
trigger.update!(owner: user)
|
|
|
|
end
|
2017-03-07 08:02:56 -05:00
|
|
|
|
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
|
|
|
|
|
2019-06-25 07:41:11 -04:00
|
|
|
it { is_expected.to be_allowed(:manage_trigger) }
|
|
|
|
it { is_expected.to be_allowed(:admin_trigger) }
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when owner is another user' do
|
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
|
|
|
|
|
2019-06-25 07:41:11 -04:00
|
|
|
it { is_expected.to be_allowed(:manage_trigger) }
|
|
|
|
it { is_expected.not_to be_allowed(:admin_trigger) }
|
2017-03-07 08:02:56 -05:00
|
|
|
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
|
|
|
|
|
2019-06-25 07:41:11 -04:00
|
|
|
it { is_expected.not_to be_allowed(:manage_trigger) }
|
|
|
|
it { is_expected.not_to be_allowed(:admin_trigger) }
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not member of the project' do
|
2019-06-25 07:41:11 -04:00
|
|
|
it { is_expected.not_to be_allowed(:manage_trigger) }
|
|
|
|
it { is_expected.not_to be_allowed(:admin_trigger) }
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|