BigW Consortium Gitlab

_commit_box.html.haml_spec.rb 1.99 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'projects/commit/_commit_box.html.haml', :view do
4
  let(:user) { create(:user) }
5
  let(:project) { create(:project, :repository) }
6 7 8 9

  before do
    assign(:project, project)
    assign(:commit, project.commit)
10
    allow(view).to receive(:can_collaborate_with_project?).and_return(false)
11 12 13 14 15
  end

  it 'shows the commit SHA' do
    render

Victor Wu committed
16
    expect(rendered).to have_text("#{Commit.truncate_sha(project.commit.sha)}")
17 18
  end

19 20 21 22 23 24
  context 'when there is a pipeline present' do
    context 'when there are multiple pipelines for a commit' do
      it 'shows the last pipeline' do
        create(:ci_pipeline, project: project, sha: project.commit.id, status: 'success')
        create(:ci_pipeline, project: project, sha: project.commit.id, status: 'canceled')
        third_pipeline = create(:ci_pipeline, project: project, sha: project.commit.id, status: 'failed')
25

26 27 28 29 30
        render

        expect(rendered).to have_text("Pipeline ##{third_pipeline.id} failed")
      end
    end
31

32 33 34 35 36 37 38 39 40 41 42 43 44
    context 'when pipeline for the commit is blocked' do
      let!(:pipeline) do
        create(:ci_pipeline, :blocked, project: project,
                                       sha: project.commit.id)
      end

      it 'shows correct pipeline description' do
        render

        expect(rendered).to have_text "Pipeline ##{pipeline.id} " \
                                      'waiting for manual action'
      end
    end
45
  end
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

  context 'viewing a commit' do
    context 'as a developer' do
      before do
        expect(view).to receive(:can_collaborate_with_project?).and_return(true)
      end

      it 'has a link to create a new tag' do
        render

        expect(rendered).to have_link('Tag')
      end
    end

    context 'as a non-developer' do
      before do
        expect(view).to receive(:can_collaborate_with_project?).and_return(false)
      end

      it 'does not have a link to create a new tag' do
        render

        expect(rendered).not_to have_link('Tag')
      end
    end
  end
72
end