2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-06 06:01:16 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe GenericCommitStatus do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-01-17 08:40:50 -05:00
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
let(:external_url) { 'http://example.gitlab.com/status' }
|
2016-12-14 04:21:16 -05:00
|
|
|
|
|
|
|
let(:generic_commit_status) do
|
2017-01-17 08:40:50 -05:00
|
|
|
create(:generic_commit_status, pipeline: pipeline,
|
|
|
|
target_url: external_url)
|
2016-12-14 04:21:16 -05:00
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2017-01-18 06:02:44 -05:00
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_length_of(:target_url).is_at_most(255) }
|
|
|
|
it { is_expected.to allow_value(nil).for(:target_url) }
|
|
|
|
it { is_expected.to allow_value('http://gitlab.com/s').for(:target_url) }
|
|
|
|
it { is_expected.not_to allow_value('javascript:alert(1)').for(:target_url) }
|
|
|
|
end
|
|
|
|
|
2020-01-30 16:08:47 -05:00
|
|
|
describe '#name_uniqueness_across_types' do
|
|
|
|
let(:attributes) { {} }
|
|
|
|
let(:commit_status) { described_class.new(attributes) }
|
|
|
|
let(:status_name) { 'test-job' }
|
|
|
|
|
|
|
|
subject(:errors) { commit_status.errors[:name] }
|
|
|
|
|
|
|
|
shared_examples 'it does not have uniqueness errors' do
|
|
|
|
it 'does not return errors' do
|
|
|
|
commit_status.valid?
|
|
|
|
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without attributes' do
|
|
|
|
it_behaves_like 'it does not have uniqueness errors'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with only a pipeline' do
|
|
|
|
let(:attributes) { { pipeline: pipeline } }
|
|
|
|
|
|
|
|
context 'without name' do
|
|
|
|
it_behaves_like 'it does not have uniqueness errors'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with only a name' do
|
|
|
|
let(:attributes) { { name: status_name } }
|
|
|
|
|
|
|
|
context 'without pipeline' do
|
|
|
|
it_behaves_like 'it does not have uniqueness errors'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with pipeline and name' do
|
|
|
|
let(:attributes) do
|
|
|
|
{
|
|
|
|
pipeline: pipeline,
|
|
|
|
name: status_name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without other statuses' do
|
|
|
|
it_behaves_like 'it does not have uniqueness errors'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with generic statuses' do
|
|
|
|
before do
|
|
|
|
create(:generic_commit_status, pipeline: pipeline, name: status_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'it does not have uniqueness errors'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with ci_build statuses' do
|
|
|
|
before do
|
|
|
|
create(:ci_build, pipeline: pipeline, name: status_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns name error' do
|
|
|
|
expect(commit_status).to be_invalid
|
|
|
|
is_expected.to include('has already been taken')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#context' do
|
2015-10-06 06:01:16 -04:00
|
|
|
subject { generic_commit_status.context }
|
2017-06-14 14:18:56 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
generic_commit_status.context = 'my_context'
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
|
|
|
|
it { is_expected.to eq(generic_commit_status.name) }
|
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#tags' do
|
2015-10-06 06:01:16 -04:00
|
|
|
subject { generic_commit_status.tags }
|
|
|
|
|
|
|
|
it { is_expected.to eq([:external]) }
|
|
|
|
end
|
|
|
|
|
2016-12-14 04:21:16 -05:00
|
|
|
describe '#detailed_status' do
|
|
|
|
let(:user) { create(:user) }
|
2017-01-17 08:40:50 -05:00
|
|
|
let(:status) { generic_commit_status.detailed_status(user) }
|
2016-12-14 04:21:16 -05:00
|
|
|
|
|
|
|
it 'returns detailed status object' do
|
2017-01-17 08:40:50 -05:00
|
|
|
expect(status).to be_a Gitlab::Ci::Status::Success
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has ability to see datails' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2017-01-17 08:40:50 -05:00
|
|
|
|
|
|
|
it 'details path points to an external URL' do
|
|
|
|
expect(status).to have_details
|
|
|
|
expect(status.details_path).to eq external_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user should not see details' do
|
|
|
|
it 'does not have details' do
|
|
|
|
expect(status).not_to have_details
|
|
|
|
end
|
2016-12-14 04:21:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe 'set_default_values' do
|
2015-10-06 06:01:16 -04:00
|
|
|
before do
|
|
|
|
generic_commit_status.context = nil
|
|
|
|
generic_commit_status.stage = nil
|
|
|
|
generic_commit_status.save
|
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#context' do
|
2015-10-06 06:01:16 -04:00
|
|
|
subject { generic_commit_status.context }
|
|
|
|
|
2016-05-23 19:37:59 -04:00
|
|
|
it { is_expected.not_to be_nil }
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#stage' do
|
2015-10-06 06:01:16 -04:00
|
|
|
subject { generic_commit_status.stage }
|
|
|
|
|
2016-05-23 19:37:59 -04:00
|
|
|
it { is_expected.not_to be_nil }
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
2020-01-30 16:08:47 -05:00
|
|
|
|
|
|
|
describe '#stage_idx' do
|
|
|
|
subject { generic_commit_status.stage_idx }
|
|
|
|
|
|
|
|
it { is_expected.not_to be_nil }
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
2018-05-16 16:58:20 -04:00
|
|
|
|
|
|
|
describe '#present' do
|
|
|
|
subject { generic_commit_status.present }
|
|
|
|
|
|
|
|
it { is_expected.to be_a(GenericCommitStatusPresenter) }
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|