2015-08-26 01:42:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 09:50:51 +00:00
|
|
|
describe Ci::Trigger, models: true do
|
2017-03-05 17:23:42 +00:00
|
|
|
let(:project) { create :empty_project }
|
|
|
|
|
|
|
|
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) }
|
2017-03-29 11:49:47 +00:00
|
|
|
it { is_expected.to have_one(:trigger_schedule) }
|
2017-03-05 17:23:42 +00:00
|
|
|
end
|
2015-08-26 01:42:46 +00:00
|
|
|
|
|
|
|
describe 'before_validation' do
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'sets an random token if none provided' do
|
2017-03-05 17:23:42 +00:00
|
|
|
trigger = create(:ci_trigger_without_token, project: project)
|
|
|
|
|
2015-09-10 13:52:52 +00:00
|
|
|
expect(trigger.token).not_to be_nil
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
2017-04-06 17:09:53 +00:00
|
|
|
it 'does not set a random token if one provided' do
|
|
|
|
trigger = create(:ci_trigger, project: project, token: 'token')
|
2017-03-05 17:23:42 +00:00
|
|
|
|
2015-09-10 13:52:52 +00:00
|
|
|
expect(trigger.token).to eq('token')
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
end
|
2017-03-07 13:02:56 +00: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 '#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
|
|
|
|
let(:trigger) { create(:ci_trigger, owner: owner, project: project) }
|
|
|
|
|
|
|
|
context 'when owner is blank' do
|
|
|
|
let(:owner) { nil }
|
|
|
|
|
|
|
|
subject { trigger.can_access_project? }
|
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when owner is set' do
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
|
|
|
|
subject { trigger.can_access_project? }
|
|
|
|
|
|
|
|
context 'and is member of the project' do
|
|
|
|
before do
|
|
|
|
project.team << [owner, :developer]
|
|
|
|
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-08-26 01:42:46 +00:00
|
|
|
end
|