summaryrefslogtreecommitdiff
path: root/spec/views/projects/commit/_commit_box.html.haml_spec.rb
blob: f2919f20e855db148189f35813c3e12be48f3622 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'spec_helper'

describe 'projects/commit/_commit_box.html.haml' do
  include Devise::Test::ControllerHelpers

  let(:user) { create(:user) }
  let(:project) { create(:project) }

  before do
    assign(:project, project)
    assign(:commit, project.commit)
    allow(view).to receive(:can_collaborate_with_project?).and_return(false)
  end

  it 'shows the commit SHA' do
    render

    expect(rendered).to have_text("#{Commit.truncate_sha(project.commit.sha)}")
  end

  it 'shows the last pipeline that ran for the commit' 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')

    render

    expect(rendered).to have_text("Pipeline ##{third_pipeline.id} for #{Commit.truncate_sha(project.commit.sha)} failed")
  end

  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
end