BigW Consortium Gitlab

_badge.html.haml_spec.rb 2.32 KB
Newer Older
1 2 3 4 5 6 7 8
require 'spec_helper'

describe 'ci/status/_badge', :view do
  let(:user) { create(:user) }
  let(:project) { create(:empty_project, :private) }
  let(:pipeline) { create(:ci_pipeline, project: project) }

  context 'when rendering status for build' do
9 10
    let(:build) do
      create(:ci_build, :success, pipeline: pipeline)
11 12
    end

13
    context 'when user has ability to see details' do
14
      before do
15
        project.add_developer(user)
16 17 18
      end

      it 'has link to build details page' do
19
        details_path = project_job_path(project, build)
20 21 22

        render_status(build)

23 24 25 26
        expect(rendered).to have_link 'passed', href: details_path
      end
    end

27
    context 'when user do not have ability to see build details' do
28 29 30
      before do
        render_status(build)
      end
31 32 33 34 35 36 37 38 39 40 41 42

      it 'contains build status text' do
        expect(rendered).to have_content 'passed'
      end

      it 'does not contain links' do
        expect(rendered).not_to have_link 'passed'
      end
    end
  end

  context 'when rendering status for external job' do
43 44 45 46
    context 'when user has ability to see commit status details' do
      before do
        project.add_developer(user)
      end
47

48 49 50 51 52 53
      context 'status has external target url' do
        before do
          external_job = create(:generic_commit_status,
                                status: :running,
                                pipeline: pipeline,
                                target_url: 'http://gitlab.com')
54

55 56
          render_status(external_job)
        end
57

58 59 60
        it 'contains valid commit status text' do
          expect(rendered).to have_content 'running'
        end
61

62 63 64
        it 'has link to external status page' do
          expect(rendered).to have_link 'running', href: 'http://gitlab.com'
        end
65 66
      end

67 68 69
      context 'status do not have external target url' do
        before do
          external_job = create(:generic_commit_status, status: :canceled)
70

71 72 73 74 75 76
          render_status(external_job)
        end

        it 'contains valid commit status text' do
          expect(rendered).to have_content 'canceled'
        end
77

78 79 80
        it 'has link to external status page' do
          expect(rendered).not_to have_link 'canceled'
        end
81 82 83 84
      end
    end
  end

85
  def render_status(resource)
86 87 88
    render 'ci/status/badge', status: resource.detailed_status(user)
  end
end