2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Ci::Trigger do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create :project }
|
2017-03-05 12:23:42 -05:00
|
|
|
|
|
|
|
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-08-25 21:42:46 -04:00
|
|
|
|
2020-01-14 07:07:41 -05:00
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:owner) }
|
|
|
|
end
|
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
describe 'before_validation' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'sets an random token if none provided' do
|
2017-03-05 12:23:42 -05:00
|
|
|
trigger = create(:ci_trigger_without_token, project: project)
|
|
|
|
|
2015-09-10 09:52:52 -04:00
|
|
|
expect(trigger.token).not_to be_nil
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
2017-04-06 13:09:53 -04:00
|
|
|
it 'does not set a random token if one provided' do
|
|
|
|
trigger = create(:ci_trigger, project: project, token: 'token')
|
2017-03-05 12:23:42 -05:00
|
|
|
|
2015-09-10 09:52:52 -04:00
|
|
|
expect(trigger.token).to eq('token')
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
end
|
2017-03-07 08:02:56 -05:00
|
|
|
|
|
|
|
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 '#can_access_project?' do
|
2019-06-25 07:41:11 -04:00
|
|
|
let(:owner) { create(:user) }
|
2017-03-07 08:02:56 -05:00
|
|
|
let(:trigger) { create(:ci_trigger, owner: owner, project: project) }
|
|
|
|
|
2020-01-14 07:07:41 -05:00
|
|
|
subject { trigger.can_access_project? }
|
|
|
|
|
|
|
|
context 'and is member of the project' do
|
2019-06-25 07:41:11 -04:00
|
|
|
before do
|
2020-01-14 07:07:41 -05:00
|
|
|
project.add_developer(owner)
|
2019-06-25 07:41:11 -04:00
|
|
|
end
|
2017-03-07 08:02:56 -05:00
|
|
|
|
2020-01-14 07:07:41 -05:00
|
|
|
it { is_expected.to eq(true) }
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
2020-01-14 07:07:41 -05:00
|
|
|
context 'and is not member of the project' do
|
|
|
|
it { is_expected.to eq(false) }
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|