generic_commit_status_spec.rb 2.24 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'spec_helper'

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

  let(:generic_commit_status) do
11 12
    create(:generic_commit_status, pipeline: pipeline,
                                   target_url: external_url)
13
  end
14

15 16 17 18 19 20 21
  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

22
  describe '#context' do
23
    subject { generic_commit_status.context }
24 25 26 27

    before do
      generic_commit_status.context = 'my_context'
    end
28 29 30 31

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

32
  describe '#tags' do
33 34 35 36 37
    subject { generic_commit_status.tags }

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

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

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

    context 'when user has ability to see datails' do
47
      before do
48
        project.add_developer(user)
49
      end
50 51 52 53 54 55 56 57 58 59 60

      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
61 62 63
    end
  end

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

71
    describe '#context' do
72 73
      subject { generic_commit_status.context }

74
      it { is_expected.not_to be_nil }
75 76
    end

77
    describe '#stage' do
78 79
      subject { generic_commit_status.stage }

80
      it { is_expected.not_to be_nil }
81 82
    end
  end
83 84 85 86 87 88

  describe '#present' do
    subject { generic_commit_status.present }

    it { is_expected.to be_a(GenericCommitStatusPresenter) }
  end
89
end