debian-mirror-gitlab/spec/policies/ci/trigger_policy_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.4 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.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) }
2019-09-30 21:07:59 +05:30
let(:trigger) { create(:ci_trigger, project: project, owner: create(:user)) }
2017-08-17 22:00:37 +05:30
2019-09-30 21:07:59 +05:30
subject { described_class.new(user, trigger) }
2017-08-17 22:00:37 +05:30
describe '#rules' do
context 'when owner is an user' do
2019-09-30 21:07:59 +05:30
before do
trigger.update!(owner: user)
end
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
context 'when user is maintainer of the project' do
2017-08-17 22:00:37 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-08-17 22:00:37 +05:30
end
2019-09-30 21:07:59 +05:30
it { is_expected.to be_allowed(:manage_trigger) }
it { is_expected.to be_allowed(:admin_trigger) }
2017-08-17 22:00:37 +05:30
end
end
context 'when owner is another user' do
2018-11-18 11:00:15 +05:30
context 'when user is maintainer of the project' do
2017-08-17 22:00:37 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-08-17 22:00:37 +05:30
end
2019-09-30 21:07:59 +05:30
it { is_expected.to be_allowed(:manage_trigger) }
it { is_expected.not_to be_allowed(:admin_trigger) }
2017-08-17 22:00:37 +05:30
end
context 'when user is developer of the project' do
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2017-08-17 22:00:37 +05:30
end
2019-09-30 21:07:59 +05:30
it { is_expected.not_to be_allowed(:manage_trigger) }
it { is_expected.not_to be_allowed(:admin_trigger) }
2017-08-17 22:00:37 +05:30
end
context 'when user is not member of the project' do
2019-09-30 21:07:59 +05:30
it { is_expected.not_to be_allowed(:manage_trigger) }
it { is_expected.not_to be_allowed(:admin_trigger) }
2017-08-17 22:00:37 +05:30
end
end
end
end