2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Ci::Trigger do
|
|
|
|
let(:project) { create :project }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
it { is_expected.to belong_to(:owner) }
|
|
|
|
it { is_expected.to have_many(:trigger_requests) }
|
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
|
|
|
|
describe 'before_validation' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'sets an random token if none provided' do
|
2017-08-17 22:00:37 +05:30
|
|
|
trigger = create(:ci_trigger_without_token, project: project)
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
expect(trigger.token).not_to be_nil
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'does not set a random token if one provided' do
|
|
|
|
trigger = create(:ci_trigger, project: project, token: 'token')
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
expect(trigger.token).to eq('token')
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#short_token' do
|
|
|
|
let(:trigger) { create(:ci_trigger, token: '12345678') }
|
|
|
|
|
|
|
|
subject { trigger.short_token }
|
|
|
|
|
|
|
|
it 'returns shortened token' do
|
|
|
|
is_expected.to eq('1234')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#legacy?' do
|
|
|
|
let(:trigger) { create(:ci_trigger, owner: owner, project: project) }
|
|
|
|
|
|
|
|
subject { trigger }
|
|
|
|
|
|
|
|
context 'when owner is blank' do
|
|
|
|
let(:owner) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to be_legacy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when owner is set' do
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
|
|
|
|
it { is_expected.not_to be_legacy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#can_access_project?' do
|
2019-09-30 21:07:59 +05:30
|
|
|
let(:owner) { create(:user) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:trigger) { create(:ci_trigger, owner: owner, project: project) }
|
|
|
|
|
|
|
|
context 'when owner is blank' do
|
2019-09-30 21:07:59 +05:30
|
|
|
before do
|
|
|
|
stub_feature_flags(use_legacy_pipeline_triggers: false)
|
|
|
|
trigger.update_attribute(:owner, nil)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
subject { trigger.can_access_project? }
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
|
|
|
|
context 'when :use_legacy_pipeline_triggers feature flag is enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(use_legacy_pipeline_triggers: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { trigger.can_access_project? }
|
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when owner is set' do
|
|
|
|
subject { trigger.can_access_project? }
|
|
|
|
|
|
|
|
context 'and is member of the project' do
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(owner)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and is not member of the project' do
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|