BigW Consortium Gitlab

commits_spec.rb 6 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
    let!(:pipeline) do
15 16 17 18 19
      create(:ci_pipeline,
             project: project,
             ref: project.default_branch,
             sha: project.commit.sha,
             status: :success)
Kamil Trzcinski committed
20 21
    end

22
    context 'commit status is Generic Commit Status' do
23
      let!(:status) { create(:generic_commit_status, pipeline: pipeline) }
24

25 26 27 28
      before do
        project.team << [@user, :reporter]
      end

29 30
      describe 'Commit builds' do
        before do
31
          visit ci_status_path(pipeline)
32
        end
33

34
        it { expect(page).to have_content pipeline.sha[0..7] }
35 36 37 38 39 40

        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
41 42 43 44
        end
      end
    end

45
    context 'commit status is Ci Build' do
46
      let!(:build) { create(:ci_build, pipeline: pipeline) }
47
      let(:artifacts_file) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
48

49
      context 'when logged as developer' do
50
        before do
51
          project.team << [@user, :developer]
52
        end
53

54
        describe 'Project commits' do
55 56 57 58 59 60 61 62
          let!(:pipeline_from_other_branch) do
            create(:ci_pipeline,
                   project: project,
                   ref: 'fix',
                   sha: project.commit.sha,
                   status: :failed)
          end

63 64
          before do
            visit namespace_project_commits_path(project.namespace, project, :master)
65
          end
66

67
          it 'shows correct build status from default branch' do
68
            page.within("//li[@id='commit-#{pipeline.short_sha}']") do
69 70
              expect(page).to have_css('.ci-status-link')
              expect(page).to have_css('.ci-status-icon-success')
71 72
            end
          end
73
        end
74

75 76
        describe 'Commit builds' do
          before do
77
            visit ci_status_path(pipeline)
78
          end
79

Valery Sizov committed
80 81 82 83 84
          it 'shows pipeline`s data' do
            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
          end
85 86
        end

87 88 89 90
        context 'Download artifacts' do
          before do
            build.update_attributes(artifacts_file: artifacts_file)
          end
91

92
          it do
93
            visit ci_status_path(pipeline)
94 95 96
            click_on 'Download artifacts'
            expect(page.response_headers['Content-Type']).to eq(artifacts_file.content_type)
          end
97
        end
98

99 100
        describe 'Cancel all builds' do
          it 'cancels commit' do
101
            visit ci_status_path(pipeline)
102 103
            click_on 'Cancel running'
            expect(page).to have_content 'canceled'
104
          end
105
        end
106

107 108
        describe 'Cancel build' do
          it 'cancels build' do
109
            visit ci_status_path(pipeline)
Filipa Lacerda committed
110
            find('a.btn[title="Cancel"]').click
111
            expect(page).to have_content 'canceled'
112 113 114
          end
        end

115 116 117
        describe '.gitlab-ci.yml not found warning' do
          context 'ci builds enabled' do
            it "does not show warning" do
118
              visit ci_status_path(pipeline)
119 120 121 122
              expect(page).not_to have_content '.gitlab-ci.yml not found in this commit'
            end

            it 'shows warning' do
123 124
              stub_ci_pipeline_yaml_file(nil)
              visit ci_status_path(pipeline)
125 126
              expect(page).to have_content '.gitlab-ci.yml not found in this commit'
            end
127
          end
128

129 130 131
          context 'ci builds disabled' do
            before do
              stub_ci_builds_disabled
132 133
              stub_ci_pipeline_yaml_file(nil)
              visit ci_status_path(pipeline)
134 135 136 137 138
            end

            it 'does not show warning' do
              expect(page).not_to have_content '.gitlab-ci.yml not found in this commit'
            end
139
          end
140
        end
141
      end
142 143 144 145 146

      context "when logged as reporter" do
        before do
          project.team << [@user, :reporter]
          build.update_attributes(artifacts_file: artifacts_file)
147
          visit ci_status_path(pipeline)
148 149 150
        end

        it do
151 152 153
          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
154
          expect(page).to have_link('Download artifacts')
155 156
          expect(page).not_to have_link('Cancel running')
          expect(page).not_to have_link('Retry failed')
157 158 159 160 161 162 163 164 165
        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)
166
          visit ci_status_path(pipeline)
167 168 169
        end

        it do
170 171 172
          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
173 174 175
          expect(page).not_to have_link('Download artifacts')
          expect(page).not_to have_link('Cancel running')
          expect(page).not_to have_link('Retry failed')
176 177
        end
      end
178 179
    end
  end
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198

  context 'viewing commits for a branch' do
    let(:branch_name) { 'master' }
    let(:user) { create(:user) }

    before do
      project.team << [user, :master]
      login_with(user)
      visit namespace_project_commits_path(project.namespace, project, branch_name)
    end

    it 'includes the committed_date for each commit' do
      commits = project.repository.commits(branch_name)

      commits.each do |commit|
        expect(page).to have_content("committed #{commit.committed_date}")
      end
    end
  end
199
end