pipelines_spec.rb 8.09 KB
Newer Older
1 2 3 4 5 6 7 8
require 'spec_helper'

describe "Pipelines" do
  include GitlabRoutingHelper

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

Kamil Trzcinski's avatar
Kamil Trzcinski committed
9 10 11 12 13 14
  before do
    login_as(user)
    project.team << [user, :developer]
  end

  describe 'GET /:project/pipelines' do
15
    let!(:pipeline) { create(:ci_empty_pipeline, project: project, ref: 'master', status: 'running') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
16 17 18 19 20 21 22 23 24 25 26

    [:all, :running, :branches].each do |scope|
      context "displaying #{scope}" do
        let(:project) { create(:project) }

        before { visit namespace_project_pipelines_path(project.namespace, project, scope: scope) }

        it { expect(page).to have_content(pipeline.short_sha) }
      end
    end

27 28 29 30 31 32
    context 'anonymous access' do
      before { visit namespace_project_pipelines_path(project.namespace, project) }

      it { expect(page).to have_http_status(:success) }
    end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
33
    context 'cancelable pipeline' do
34
      let!(:build) { create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
35

36
      before do
37
        build.run
38 39
        visit namespace_project_pipelines_path(project.namespace, project)
      end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
40 41 42 43 44 45 46

      it { expect(page).to have_link('Cancel') }
      it { expect(page).to have_selector('.ci-running') }

      context 'when canceling' do
        before { click_link('Cancel') }

47
        it { expect(page).not_to have_link('Cancel') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
48 49 50 51 52
        it { expect(page).to have_selector('.ci-canceled') }
      end
    end

    context 'retryable pipelines' do
53
      let!(:build) { create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
54

55
      before do
56
        build.drop
57 58
        visit namespace_project_pipelines_path(project.namespace, project)
      end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
59 60 61 62 63 64 65

      it { expect(page).to have_link('Retry') }
      it { expect(page).to have_selector('.ci-failed') }

      context 'when retrying' do
        before { click_link('Retry') }

66
        it { expect(page).not_to have_link('Retry') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
67
        it { expect(page).to have_selector('.ci-running') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
68 69 70
      end
    end

71 72 73 74 75
    context 'with manual actions' do
      let!(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'manual build', stage: 'test', commands: 'test') }

      before { visit namespace_project_pipelines_path(project.namespace, project) }

76
      it { expect(page).to have_link('Manual build') }
77 78

      context 'when playing' do
79
        before { click_link('Manual build') }
80 81 82 83 84

        it { expect(manual.reload).to be_pending }
      end
    end

85 86
    context 'for generic statuses' do
      context 'when running' do
87
        let!(:running) { create(:generic_commit_status, status: 'running', pipeline: pipeline, stage: 'test') }
88

89 90 91
        before do
          visit namespace_project_pipelines_path(project.namespace, project)
        end
92

93
        it 'is not cancelable' do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
94
          expect(page).not_to have_link('Cancel')
95 96
        end

97
        it 'has pipeline running' do
98 99 100 101 102
          expect(page).to have_selector('.ci-running')
        end
      end

      context 'when failed' do
103
        let!(:status) { create(:generic_commit_status, :pending, pipeline: pipeline, stage: 'test') }
104

105
        before do
106
          status.drop
107 108
          visit namespace_project_pipelines_path(project.namespace, project)
        end
109

110
        it 'is not retryable' do
Kamil Trzcinski's avatar
Kamil Trzcinski committed
111
          expect(page).not_to have_link('Retry')
112 113
        end

114
        it 'has failed pipeline' do
115 116 117 118 119
          expect(page).to have_selector('.ci-failed')
        end
      end
    end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
120 121
    context 'downloadable pipelines' do
      context 'with artifacts' do
122
        let!(:with_artifacts) { create(:ci_build, :artifacts, :success, pipeline: pipeline, name: 'rspec tests', stage: 'test') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
123 124

        before { visit namespace_project_pipelines_path(project.namespace, project) }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
125 126 127 128

        it { expect(page).to have_selector('.build-artifacts') }
        it { expect(page).to have_link(with_artifacts.name) }
      end
129

130 131 132 133 134 135 136 137
      context 'with artifacts expired' do
        let!(:with_artifacts_expired) { create(:ci_build, :artifacts_expired, :success, pipeline: pipeline, name: 'rspec', stage: 'test') }

        before { visit namespace_project_pipelines_path(project.namespace, project) }

        it { expect(page).not_to have_selector('.build-artifacts') }
      end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
138
      context 'without artifacts' do
139
        let!(:without_artifacts) { create(:ci_build, :success, pipeline: pipeline, name: 'rspec', stage: 'test') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
140

141 142
        before { visit namespace_project_pipelines_path(project.namespace, project) }

143
        it { expect(page).not_to have_selector('.build-artifacts') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
144 145
      end
    end
146 147
  end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
148
  describe 'GET /:project/pipelines/:id' do
Annabel Dunstone Gray's avatar
Annabel Dunstone Gray committed
149 150
    let(:project) { create(:project) }
    let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id) }
151 152

    before do
153 154 155
      @success = create(:ci_build, :success, pipeline: pipeline, stage: 'build', name: 'build')
      @failed = create(:ci_build, :failed, pipeline: pipeline, stage: 'test', name: 'test', commands: 'test')
      @running = create(:ci_build, :running, pipeline: pipeline, stage: 'deploy', name: 'deploy')
156
      @manual = create(:ci_build, :manual, pipeline: pipeline, stage: 'deploy', name: 'manual build')
157
      @external = create(:generic_commit_status, status: 'success', pipeline: pipeline, name: 'jenkins', stage: 'external')
158 159
    end

Annabel Dunstone Gray's avatar
Annabel Dunstone Gray committed
160
    before { visit namespace_project_pipeline_path(project.namespace, project, pipeline) }
161

162
    it 'shows a list of builds' do
163
      expect(page).to have_content('Test')
Kamil Trzcinski's avatar
Kamil Trzcinski committed
164 165 166 167 168 169 170
      expect(page).to have_content(@success.id)
      expect(page).to have_content('Deploy')
      expect(page).to have_content(@failed.id)
      expect(page).to have_content(@running.id)
      expect(page).to have_content(@external.id)
      expect(page).to have_content('Retry failed')
      expect(page).to have_content('Cancel running')
171
      expect(page).to have_link('Play')
Kamil Trzcinski's avatar
Kamil Trzcinski committed
172 173 174
    end

    context 'retrying builds' do
175
      it { expect(page).not_to have_content('retried') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
176 177 178 179

      context 'when retrying' do
        before { click_on 'Retry failed' }

180
        it { expect(page).not_to have_content('Retry failed') }
181
        it { expect(page).to have_selector('.retried') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
182 183 184 185
      end
    end

    context 'canceling builds' do
186
      it { expect(page).not_to have_selector('.ci-canceled') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
187 188 189 190

      context 'when canceling' do
        before { click_on 'Cancel running' }

191
        it { expect(page).not_to have_content('Cancel running') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
192 193 194
        it { expect(page).to have_selector('.ci-canceled') }
      end
    end
195 196

    context 'playing manual build' do
197 198 199 200 201
      before do
        within '.pipeline-holder' do
          click_link('Play')
        end
      end
202 203 204

      it { expect(@manual.reload).to be_pending }
    end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
205 206 207 208 209 210 211 212
  end

  describe 'POST /:project/pipelines' do
    let(:project) { create(:project) }

    before { visit new_namespace_project_pipeline_path(project.namespace, project) }

    context 'for valid commit' do
ubudzisz's avatar
ubudzisz committed
213
      before { fill_in('pipeline[ref]', with: 'master') }
214 215

      context 'with gitlab-ci.yml' do
216
        before { stub_ci_pipeline_to_return_yaml_file }
217

218
        it { expect{ click_on 'Create pipeline' }.to change{ Ci::Pipeline.count }.by(1) }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
219
      end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
220

221 222 223 224 225
      context 'without gitlab-ci.yml' do
        before { click_on 'Create pipeline' }

        it { expect(page).to have_content('Missing .gitlab-ci.yml file') }
      end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
226 227 228 229
    end

    context 'for invalid commit' do
      before do
ubudzisz's avatar
ubudzisz committed
230
        fill_in('pipeline[ref]', with: 'invalid-reference')
Kamil Trzcinski's avatar
Kamil Trzcinski committed
231 232 233 234 235
        click_on 'Create pipeline'
      end

      it { expect(page).to have_content('Reference not found') }
    end
236
  end
ubudzisz's avatar
ubudzisz committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262

  describe 'Create pipelines', feature: true do
    let(:project) { create(:project) }

    before do
      visit new_namespace_project_pipeline_path(project.namespace, project)
    end

    describe 'new pipeline page' do
      it 'has field to add a new pipeline' do
        expect(page).to have_field('pipeline[ref]')
        expect(page).to have_content('Create for')
      end
    end

    describe 'find pipelines' do
      it 'shows filtered pipelines', js: true do
        fill_in('pipeline[ref]', with: 'fix')
        find('input#ref').native.send_keys(:keydown)

        within('.ui-autocomplete') do
          expect(page).to have_selector('li', text: 'fix')
        end
      end
    end
  end
263
end