BigW Consortium Gitlab

generic_commit_status_spec.rb 2.08 KB
Newer Older
1 2
require 'spec_helper'

3
describe GenericCommitStatus do
4
  let(:project) { create(:project) }
5 6
  let(:pipeline) { create(:ci_pipeline, project: project) }
  let(:external_url) { 'http://example.gitlab.com/status' }
7 8

  let(:generic_commit_status) do
9 10
    create(:generic_commit_status, pipeline: pipeline,
                                   target_url: external_url)
11
  end
12

13 14 15 16 17 18 19
  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

20
  describe '#context' do
21
    subject { generic_commit_status.context }
22 23 24 25

    before do
      generic_commit_status.context = 'my_context'
    end
26 27 28 29

    it { is_expected.to eq(generic_commit_status.name) }
  end

30
  describe '#tags' do
31 32 33 34 35
    subject { generic_commit_status.tags }

    it { is_expected.to eq([:external]) }
  end

36 37
  describe '#detailed_status' do
    let(:user) { create(:user) }
38
    let(:status) { generic_commit_status.detailed_status(user) }
39 40

    it 'returns detailed status object' do
41 42 43 44
      expect(status).to be_a Gitlab::Ci::Status::Success
    end

    context 'when user has ability to see datails' do
45 46 47
      before do
        project.team << [user, :developer]
      end
48 49 50 51 52 53 54 55 56 57 58

      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
59 60 61
    end
  end

62
  describe 'set_default_values' do
63 64 65 66 67 68
    before do
      generic_commit_status.context = nil
      generic_commit_status.stage = nil
      generic_commit_status.save
    end

69
    describe '#context' do
70 71
      subject { generic_commit_status.context }

72
      it { is_expected.not_to be_nil }
73 74
    end

75
    describe '#stage' do
76 77
      subject { generic_commit_status.stage }

78
      it { is_expected.not_to be_nil }
79 80 81
    end
  end
end