BigW Consortium Gitlab

commits_spec.rb 5.05 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Commits' do
4
  include CiStatusHelper
5

6 7
  let(:project) { create(:project) }

8
  describe 'CI' do
9
    before do
10
      login_as :user
11
      stub_ci_pipeline_to_return_yaml_file
12 13
    end

14 15
    let!(:pipeline) do
      FactoryGirl.create :ci_pipeline, project: project, sha: project.commit.sha
Kamil Trzcinski committed
16 17
    end

18
    context 'commit status is Generic Commit Status' do
19
      let!(:status) { FactoryGirl.create :generic_commit_status, pipeline: pipeline }
20

21 22 23 24
      before do
        project.team << [@user, :reporter]
      end

25 26
      describe 'Commit builds' do
        before do
27
          visit ci_status_path(pipeline)
28
        end
29

30
        it { expect(page).to have_content pipeline.sha[0..7] }
31 32 33 34 35 36

        it 'contains generic commit status build' do
          page.within('.table-holder') do
            expect(page).to have_content "##{status.id}" # build id
            expect(page).to have_content 'generic'       # build name
          end
37 38 39 40
        end
      end
    end

41
    context 'commit status is Ci Build' do
42
      let!(:build) { FactoryGirl.create :ci_build, pipeline: pipeline }
43
      let(:artifacts_file) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
44

45
      context 'when logged as developer' do
46
        before do
47
          project.team << [@user, :developer]
48
        end
49

50 51 52
        describe 'Project commits' do
          before do
            visit namespace_project_commits_path(project.namespace, project, :master)
53
          end
54

55
          it 'should show build status' do
56
            page.within("//li[@id='commit-#{pipeline.short_sha}']") do
57 58 59
              expect(page).to have_css(".ci-status-link")
            end
          end
60
        end
61

62 63
        describe 'Commit builds' do
          before do
64
            visit ci_status_path(pipeline)
65
          end
66

67 68 69
          it { expect(page).to have_content pipeline.sha[0..7] }
          it { expect(page).to have_content pipeline.git_commit_message }
          it { expect(page).to have_content pipeline.git_author_name }
70 71
        end

72 73 74 75
        context 'Download artifacts' do
          before do
            build.update_attributes(artifacts_file: artifacts_file)
          end
76

77
          it do
78
            visit ci_status_path(pipeline)
79 80 81
            click_on 'Download artifacts'
            expect(page.response_headers['Content-Type']).to eq(artifacts_file.content_type)
          end
82
        end
83

84 85
        describe 'Cancel all builds' do
          it 'cancels commit' do
86
            visit ci_status_path(pipeline)
87 88
            click_on 'Cancel running'
            expect(page).to have_content 'canceled'
89
          end
90
        end
91

92 93
        describe 'Cancel build' do
          it 'cancels build' do
94
            visit ci_status_path(pipeline)
95 96
            click_on 'Cancel'
            expect(page).to have_content 'canceled'
97 98 99
          end
        end

100 101 102
        describe '.gitlab-ci.yml not found warning' do
          context 'ci builds enabled' do
            it "does not show warning" do
103
              visit ci_status_path(pipeline)
104 105 106 107
              expect(page).not_to have_content '.gitlab-ci.yml not found in this commit'
            end

            it 'shows warning' do
108 109
              stub_ci_pipeline_yaml_file(nil)
              visit ci_status_path(pipeline)
110 111
              expect(page).to have_content '.gitlab-ci.yml not found in this commit'
            end
112
          end
113

114 115 116
          context 'ci builds disabled' do
            before do
              stub_ci_builds_disabled
117 118
              stub_ci_pipeline_yaml_file(nil)
              visit ci_status_path(pipeline)
119 120 121 122 123
            end

            it 'does not show warning' do
              expect(page).not_to have_content '.gitlab-ci.yml not found in this commit'
            end
124
          end
125
        end
126
      end
127 128 129 130 131

      context "when logged as reporter" do
        before do
          project.team << [@user, :reporter]
          build.update_attributes(artifacts_file: artifacts_file)
132
          visit ci_status_path(pipeline)
133 134 135
        end

        it do
136 137 138
          expect(page).to have_content pipeline.sha[0..7]
          expect(page).to have_content pipeline.git_commit_message
          expect(page).to have_content pipeline.git_author_name
139
          expect(page).to have_link('Download artifacts')
140 141
          expect(page).not_to have_link('Cancel running')
          expect(page).not_to have_link('Retry failed')
142 143 144 145 146 147 148 149 150
        end
      end

      context 'when accessing internal project with disallowed access' do
        before do
          project.update(
            visibility_level: Gitlab::VisibilityLevel::INTERNAL,
            public_builds: false)
          build.update_attributes(artifacts_file: artifacts_file)
151
          visit ci_status_path(pipeline)
152 153 154
        end

        it do
155 156 157
          expect(page).to have_content pipeline.sha[0..7]
          expect(page).to have_content pipeline.git_commit_message
          expect(page).to have_content pipeline.git_author_name
158 159 160
          expect(page).not_to have_link('Download artifacts')
          expect(page).not_to have_link('Cancel running')
          expect(page).not_to have_link('Retry failed')
161 162
        end
      end
163 164 165
    end
  end
end