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

3
describe 'Commits' do
4
  let(:project) { create(:project, :repository) }
5
  let(:user) { create(:user) }
6

7
  describe 'CI' do
8
    before do
9
      sign_in(user)
10
      stub_ci_pipeline_to_return_yaml_file
11 12
    end

13
    let(:creator) { create(:user) }
14

15
    let!(:pipeline) do
16 17
      create(:ci_pipeline,
             project: project,
18
             user: creator,
19 20
             ref: project.default_branch,
             sha: project.commit.sha,
21 22
             status: :success,
             created_at: 5.months.ago)
Kamil Trzcinski's avatar
Kamil Trzcinski committed
23 24
    end

25
    context 'commit status is Generic Commit Status' do
26
      let!(:status) { create(:generic_commit_status, pipeline: pipeline) }
27

28
      before do
29
        project.add_reporter(user)
30 31
      end

32 33
      describe 'Commit builds' do
        before do
34
          visit pipeline_path(pipeline)
35
        end
36

37
        it { expect(page).to have_content pipeline.sha[0..7] }
38 39 40 41 42 43

        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
44 45 46 47
        end
      end
    end

48
    context 'commit status is Ci Build' do
49
      let!(:build) { create(:ci_build, pipeline: pipeline) }
50
      let(:artifacts_file) { fixture_file_upload('spec/fixtures/banana_sample.gif', 'image/gif') }
51

52
      context 'when logged as developer' do
53
        before do
54
          project.add_developer(user)
55
        end
56

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

66
          before do
67
            visit project_commits_path(project, :master)
68
          end
69

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

78
        describe 'Commit builds', :js do
79
          before do
80
            visit pipeline_path(pipeline)
81
          end
82

Valery Sizov's avatar
Valery Sizov committed
83 84 85
          it 'shows pipeline`s data' do
            expect(page).to have_content pipeline.sha[0..7]
            expect(page).to have_content pipeline.git_commit_message
86
            expect(page).to have_content pipeline.user.name
Valery Sizov's avatar
Valery Sizov committed
87
          end
88 89
        end

90 91
        context 'Download artifacts' do
          before do
Lin Jen-Shin's avatar
Lin Jen-Shin committed
92
            build.update(legacy_artifacts_file: artifacts_file)
93
          end
94

95
          it do
96
            visit pipeline_path(pipeline)
97 98 99
            click_on 'Download artifacts'
            expect(page.response_headers['Content-Type']).to eq(artifacts_file.content_type)
          end
100
        end
101

102
        describe 'Cancel all builds' do
103
          it 'cancels commit', :js do
104
            visit pipeline_path(pipeline)
105 106
            click_on 'Cancel running'
            expect(page).to have_content 'canceled'
107
          end
108
        end
109

110
        describe 'Cancel build' do
111
          it 'cancels build', :js do
112
            visit pipeline_path(pipeline)
113
            find('.js-btn-cancel-pipeline').click
114
            expect(page).to have_content 'canceled'
115 116
          end
        end
117
      end
118 119 120

      context "when logged as reporter" do
        before do
121
          project.add_reporter(user)
Lin Jen-Shin's avatar
Lin Jen-Shin committed
122
          build.update(legacy_artifacts_file: artifacts_file)
123
          visit pipeline_path(pipeline)
124 125
        end

126
        it 'Renders header', :js do
127 128
          expect(page).to have_content pipeline.sha[0..7]
          expect(page).to have_content pipeline.git_commit_message
129
          expect(page).to have_content pipeline.user.name
130
          expect(page).not_to have_link('Cancel running')
dimitrieh's avatar
dimitrieh committed
131
          expect(page).not_to have_link('Retry')
132
        end
133 134 135 136

        it do
          expect(page).to have_link('Download artifacts')
        end
137 138
      end

139
      context 'when accessing internal project with disallowed access', :js do
140 141 142 143
        before do
          project.update(
            visibility_level: Gitlab::VisibilityLevel::INTERNAL,
            public_builds: false)
Lin Jen-Shin's avatar
Lin Jen-Shin committed
144
          build.update(legacy_artifacts_file: artifacts_file)
145
          visit pipeline_path(pipeline)
146 147 148
        end

        it do
149 150
          expect(page).to have_content pipeline.sha[0..7]
          expect(page).to have_content pipeline.git_commit_message
151
          expect(page).to have_content pipeline.user.name
152

153
          expect(page).not_to have_link('Cancel running')
dimitrieh's avatar
dimitrieh committed
154
          expect(page).not_to have_link('Retry')
155 156
        end
      end
157
    end
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190

    describe '.gitlab-ci.yml not found warning' do
      before do
        project.add_reporter(user)
      end

      context 'ci builds enabled' do
        it 'does not show warning' do
          visit pipeline_path(pipeline)

          expect(page).not_to have_content '.gitlab-ci.yml not found in this commit'
        end

        it 'shows warning' do
          stub_ci_pipeline_yaml_file(nil)

          visit pipeline_path(pipeline)

          expect(page).to have_content '.gitlab-ci.yml not found in this commit'
        end
      end

      context 'ci builds disabled' do
        it 'does not show warning' do
          stub_ci_builds_disabled
          stub_ci_pipeline_yaml_file(nil)

          visit pipeline_path(pipeline)

          expect(page).not_to have_content '.gitlab-ci.yml not found in this commit'
        end
      end
    end
191
  end
192 193 194 195 196

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

    before do
197
      project.add_maintainer(user)
198
      sign_in(user)
199
      visit project_commits_path(project, branch_name)
200 201 202
    end

    it 'includes the committed_date for each commit' do
203
      commits = project.repository.commits(branch_name, limit: 40)
204 205

      commits.each do |commit|
Annabel Dunstone Gray's avatar
Annabel Dunstone Gray committed
206
        expect(page).to have_content("authored #{commit.authored_date.strftime("%b %d, %Y")}")
207 208
      end
    end
209 210 211 212 213 214 215

    it 'shows the ref switcher with the multi-file editor enabled', :js do
      set_cookie('new_repo', 'true')
      visit project_commits_path(project, branch_name)

      expect(find('.js-project-refs-dropdown')).to have_content branch_name
    end
216
  end
217
end