BigW Consortium Gitlab

pipelines_spec.rb 8.03 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 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 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 committed
33
    context 'cancelable pipeline' do
34
      let!(:build) { create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test') }
Kamil Trzcinski committed
35

36
      before do
37
        build.run
38 39
        visit namespace_project_pipelines_path(project.namespace, project)
      end
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 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 committed
54

55
      before do
56
        build.drop
57 58
        visit namespace_project_pipelines_path(project.namespace, project)
      end
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 committed
67
        it { expect(page).to have_selector('.ci-running') }
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 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 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 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 committed
123 124

        before { visit namespace_project_pipelines_path(project.namespace, project) }
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 committed
138
      context 'without artifacts' do
139
        let!(:without_artifacts) { create(:ci_build, :success, pipeline: pipeline, name: 'rspec', stage: 'test') }
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 committed
144 145
      end
    end
146 147
  end

Kamil Trzcinski committed
148
  describe 'GET /:project/pipelines/:id' do
149
    let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master') }
150 151

    before do
152 153 154
      @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')
155
      @manual = create(:ci_build, :manual, pipeline: pipeline, stage: 'deploy', name: 'manual build')
156
      @external = create(:generic_commit_status, status: 'success', pipeline: pipeline, name: 'jenkins', stage: 'external')
157 158 159 160
    end

    before { visit namespace_project_pipeline_path(project.namespace, project, pipeline) }

161
    it 'shows a list of builds' do
162
      expect(page).to have_content('Test')
Kamil Trzcinski committed
163 164 165 166 167 168 169
      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')
170
      expect(page).to have_link('Play')
Kamil Trzcinski committed
171 172 173
    end

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

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

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

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

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

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

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

      it { expect(@manual.reload).to be_pending }
    end
Kamil Trzcinski committed
204 205 206 207 208 209 210 211
  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 committed
212
      before { fill_in('pipeline[ref]', with: 'master') }
213 214

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

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

220 221 222 223 224
      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 committed
225 226 227 228
    end

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

      it { expect(page).to have_content('Reference not found') }
    end
235
  end
ubudzisz committed
236 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

  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
262
end