BigW Consortium Gitlab

pipeline_schedules_spec.rb 10.1 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Pipeline Schedules', :js do
4 5
  include PipelineSchedulesHelper

6
  let!(:project) { create(:project, :repository) }
7
  let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project ) }
8
  let!(:pipeline) { create(:ci_pipeline, pipeline_schedule: pipeline_schedule) }
9 10 11
  let(:scope) { nil }
  let!(:user) { create(:user) }

12
  context 'logged in as master' do
Shinya Maeda committed
13
    before do
14 15
      project.add_master(user)
      gitlab_sign_in(user)
16 17
    end

18 19 20
    describe 'GET /projects/pipeline_schedules' do
      before do
        visit_pipelines_schedules
21 22
      end

23 24 25 26 27 28 29 30 31 32
      describe 'The view' do
        it 'displays the required information description' do
          page.within('.pipeline-schedule-table-row') do
            expect(page).to have_content('pipeline schedule')
            expect(find(".next-run-cell time")['data-original-title'])
              .to include(pipeline_schedule.real_next_run.strftime('%b %-d, %Y'))
            expect(page).to have_link('master')
            expect(page).to have_link("##{pipeline.id}")
          end
        end
33

34 35
        it 'creates a new scheduled pipeline' do
          click_link 'New schedule'
36

37
          expect(page).to have_content('Schedule a new pipeline')
38 39
        end

40 41 42 43 44 45
        it 'changes ownership of the pipeline' do
          click_link 'Take ownership'
          page.within('.pipeline-schedule-table-row') do
            expect(page).not_to have_content('No owner')
            expect(page).to have_link('John Doe')
          end
46 47
        end

48 49 50 51 52 53 54 55 56 57 58 59 60
        it 'edits the pipeline' do
          page.within('.pipeline-schedule-table-row') do
            click_link 'Edit'
          end

          expect(page).to have_content('Edit Pipeline Schedule')
        end

        it 'deletes the pipeline' do
          click_link 'Delete'

          expect(page).not_to have_css(".pipeline-schedule-table-row")
        end
61 62
      end

63 64 65 66 67
      context 'when ref is nil' do
        before do
          pipeline_schedule.update_attribute(:ref, nil)
          visit_pipelines_schedules
        end
68

69 70 71
        it 'shows a list of the pipeline schedules with empty ref column' do
          expect(first('.branch-name-cell').text).to eq('')
        end
72
      end
Shinya Maeda committed
73 74 75 76 77 78 79 80 81 82 83

      context 'when ref is empty' do
        before do
          pipeline_schedule.update_attribute(:ref, '')
          visit_pipelines_schedules
        end

        it 'shows a list of the pipeline schedules with empty ref column' do
          expect(first('.branch-name-cell').text).to eq('')
        end
      end
84
    end
Shinya Maeda committed
85

86
    describe 'POST /projects/pipeline_schedules/new' do
Shinya Maeda committed
87
      before do
88
        visit_new_pipeline_schedule
Shinya Maeda committed
89 90
      end

91 92 93
      it 'sets defaults for timezone and target branch' do
        expect(page).to have_button('master')
        expect(page).to have_button('UTC')
Shinya Maeda committed
94
      end
95

96 97 98
      it 'it creates a new scheduled pipeline' do
        fill_in_schedule_form
        save_pipeline_schedule
99

100 101
        expect(page).to have_content('my fancy description')
      end
102

103 104
      it 'it prevents an invalid form from being submitted' do
        save_pipeline_schedule
105

106 107
        expect(page).to have_content('This field is required')
      end
108 109
    end

110 111 112 113
    describe 'PATCH /projects/pipelines_schedules/:id/edit' do
      before do
        edit_pipeline_schedule
      end
114

115 116 117 118 119 120
      it 'it displays existing properties' do
        description = find_field('schedule_description').value
        expect(description).to eq('pipeline schedule')
        expect(page).to have_button('master')
        expect(page).to have_button('UTC')
      end
121

122 123
      it 'edits the scheduled pipeline' do
        fill_in 'schedule_description', with: 'my brand new description'
124

125
        save_pipeline_schedule
126

127 128
        expect(page).to have_content('my brand new description')
      end
129

130 131 132 133 134
      context 'when ref is nil' do
        before do
          pipeline_schedule.update_attribute(:ref, nil)
          edit_pipeline_schedule
        end
135

136 137
        it 'shows the pipeline schedule with default ref' do
          page.within('.js-target-branch-dropdown') do
Shinya Maeda committed
138 139 140 141 142 143 144 145 146 147 148 149 150
            expect(first('.dropdown-toggle-text').text).to eq('master')
          end
        end
      end

      context 'when ref is empty' do
        before do
          pipeline_schedule.update_attribute(:ref, '')
          edit_pipeline_schedule
        end

        it 'shows the pipeline schedule with default ref' do
          page.within('.js-target-branch-dropdown') do
151 152 153 154
            expect(first('.dropdown-toggle-text').text).to eq('master')
          end
        end
      end
155
    end
Shinya Maeda committed
156

157 158 159 160 161 162 163 164 165 166
    context 'when user creates a new pipeline schedule with variables' do
      background do
        visit_pipelines_schedules
        click_link 'New schedule'
        fill_in_schedule_form
        all('[name="schedule[variables_attributes][][key]"]')[0].set('AAA')
        all('[name="schedule[variables_attributes][][value]"]')[0].set('AAA123')
        all('[name="schedule[variables_attributes][][key]"]')[1].set('BBB')
        all('[name="schedule[variables_attributes][][value]"]')[1].set('BBB123')
        save_pipeline_schedule
Shinya Maeda committed
167 168
      end

169 170 171 172 173 174 175
      scenario 'user sees the new variable in edit window' do
        find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
        page.within('.pipeline-variable-list') do
          expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('AAA')
          expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('AAA123')
          expect(find(".pipeline-variable-row:nth-child(2) .pipeline-variable-key-input").value).to eq('BBB')
          expect(find(".pipeline-variable-row:nth-child(2) .pipeline-variable-value-input").value).to eq('BBB123')
Shinya Maeda committed
176 177 178
        end
      end
    end
179

180 181 182 183 184
    context 'when user edits a variable of a pipeline schedule' do
      background do
        create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule|
          create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule)
        end
185

186 187 188 189 190
        visit_pipelines_schedules
        find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
        all('[name="schedule[variables_attributes][][key]"]')[0].set('foo')
        all('[name="schedule[variables_attributes][][value]"]')[0].set('bar')
        click_button 'Save pipeline schedule'
191
      end
192

193 194 195 196 197 198
      scenario 'user sees the updated variable in edit window' do
        find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
        page.within('.pipeline-variable-list') do
          expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('foo')
          expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('bar')
        end
199
      end
Shinya Maeda committed
200
    end
201

202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
    context 'when user removes a variable of a pipeline schedule' do
      background do
        create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule|
          create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule)
        end

        visit_pipelines_schedules
        find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
        find('.pipeline-variable-list .pipeline-variable-row-remove-button').click
        click_button 'Save pipeline schedule'
      end

      scenario 'user does not see the removed variable in edit window' do
        find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
        page.within('.pipeline-variable-list') do
          expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('')
          expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('')
        end
220
      end
Shinya Maeda committed
221
    end
Shinya Maeda committed
222 223 224 225 226 227 228 229 230

    context 'when active is true and next_run_at is NULL' do
      background do
        create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule|
          pipeline_schedule.update_attribute(:cron, nil) # Consequently next_run_at will be nil
        end
      end

      scenario 'user edit and recover the problematic pipeline schedule' do
Shinya Maeda committed
231 232
        visit_pipelines_schedules
        find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
Shinya Maeda committed
233 234
        fill_in 'schedule_cron', with: '* 1 2 3 4'
        click_button 'Save pipeline schedule'
Shinya Maeda committed
235

Shinya Maeda committed
236 237 238 239 240
        page.within('.pipeline-schedule-table-row:nth-child(1)') do
          expect(page).to have_css(".next-run-cell time")
        end
      end
    end
Shinya Maeda committed
241
  end
242

243 244 245 246 247 248 249 250
  context 'logged in as non-member' do
    before do
      gitlab_sign_in(user)
    end

    describe 'GET /projects/pipeline_schedules' do
      before do
        visit_pipelines_schedules
251
      end
Shinya Maeda committed
252

253 254 255 256 257
      describe 'The view' do
        it 'does not show create schedule button' do
          expect(page).not_to have_link('New schedule')
        end
      end
Shinya Maeda committed
258
    end
259 260 261 262 263 264 265
  end

  context 'not logged in' do
    describe 'GET /projects/pipeline_schedules' do
      before do
        visit_pipelines_schedules
      end
266

267 268 269 270
      describe 'The view' do
        it 'does not show create schedule button' do
          expect(page).not_to have_link('New schedule')
        end
271
      end
272
    end
273 274 275
  end

  def visit_new_pipeline_schedule
276
    visit new_project_pipeline_schedule_path(project, pipeline_schedule)
277 278 279
  end

  def edit_pipeline_schedule
280
    visit edit_project_pipeline_schedule_path(project, pipeline_schedule)
281 282 283
  end

  def visit_pipelines_schedules
284
    visit project_pipeline_schedules_path(project, scope: scope)
285 286 287
  end

  def select_timezone
288
    find('.js-timezone-dropdown').click
289 290 291 292
    click_link 'American Samoa'
  end

  def select_target_branch
293
    find('.js-target-branch-dropdown').click
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
    click_link 'master'
  end

  def save_pipeline_schedule
    click_button 'Save pipeline schedule'
  end

  def fill_in_schedule_form
    fill_in 'schedule_description', with: 'my fancy description'
    fill_in 'schedule_cron', with: '* 1 2 3 4'

    select_timezone
    select_target_branch
  end
end