debian-mirror-gitlab/spec/models/generic_commit_status_spec.rb

88 lines
2.2 KiB
Ruby
Raw Normal View History

2015-10-24 18:46:33 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe GenericCommitStatus do
let(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:external_url) { 'http://example.gitlab.com/status' }
let(:generic_commit_status) do
create(:generic_commit_status, pipeline: pipeline,
target_url: external_url)
end
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
2015-10-24 18:46:33 +05:30
2016-08-24 12:49:21 +05:30
describe '#context' do
2015-10-24 18:46:33 +05:30
subject { generic_commit_status.context }
2017-09-10 17:25:29 +05:30
before do
generic_commit_status.context = 'my_context'
end
2015-10-24 18:46:33 +05:30
it { is_expected.to eq(generic_commit_status.name) }
end
2016-08-24 12:49:21 +05:30
describe '#tags' do
2015-10-24 18:46:33 +05:30
subject { generic_commit_status.tags }
it { is_expected.to eq([:external]) }
end
2017-08-17 22:00:37 +05:30
describe '#detailed_status' do
let(:user) { create(:user) }
let(:status) { generic_commit_status.detailed_status(user) }
it 'returns detailed status object' do
expect(status).to be_a Gitlab::Ci::Status::Success
end
context 'when user has ability to see datails' do
2017-09-10 17:25:29 +05:30
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
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
end
end
2016-08-24 12:49:21 +05:30
describe 'set_default_values' do
2015-10-24 18:46:33 +05:30
before do
generic_commit_status.context = nil
generic_commit_status.stage = nil
generic_commit_status.save
end
2016-08-24 12:49:21 +05:30
describe '#context' do
2015-10-24 18:46:33 +05:30
subject { generic_commit_status.context }
it { is_expected.not_to be_nil }
2015-10-24 18:46:33 +05:30
end
2016-08-24 12:49:21 +05:30
describe '#stage' do
2015-10-24 18:46:33 +05:30
subject { generic_commit_status.stage }
it { is_expected.not_to be_nil }
2015-10-24 18:46:33 +05:30
end
end
2018-10-15 14:42:47 +05:30
describe '#present' do
subject { generic_commit_status.present }
it { is_expected.to be_a(GenericCommitStatusPresenter) }
end
2015-10-24 18:46:33 +05:30
end