diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-04-07 16:02:13 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-04-07 16:19:11 +0200 |
commit | 21a7aed9a7330382300bc93b8927609e65ee6390 (patch) | |
tree | e5aec1003032a91e43e4eb8af61ec65e47e2ce7e /spec | |
parent | 03088552549ed1631bb16c1bf3d0bef3613ec793 (diff) | |
download | gitlab-ce-21a7aed9a7330382300bc93b8927609e65ee6390.tar.gz |
Update tests to cover trigger schedule
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/trigger_schedules.rb | 4 | ||||
-rw-r--r-- | spec/features/triggers_spec.rb | 55 | ||||
-rw-r--r-- | spec/workers/trigger_schedule_worker_spec.rb | 34 |
3 files changed, 73 insertions, 20 deletions
diff --git a/spec/factories/ci/trigger_schedules.rb b/spec/factories/ci/trigger_schedules.rb index 315bce16995..2390706fa41 100644 --- a/spec/factories/ci/trigger_schedules.rb +++ b/spec/factories/ci/trigger_schedules.rb @@ -3,9 +3,11 @@ FactoryGirl.define do trigger factory: :ci_trigger_for_trigger_schedule cron '0 1 * * *' cron_timezone Gitlab::Ci::CronParser::VALID_SYNTAX_SAMPLE_TIME_ZONE + ref 'master' + active true after(:build) do |trigger_schedule, evaluator| - trigger_schedule.update!(project: trigger_schedule.trigger.project) + trigger_schedule.project ||= trigger_schedule.trigger.project end trait :nightly do diff --git a/spec/features/triggers_spec.rb b/spec/features/triggers_spec.rb index d317bb7bec7..10bfb9098c7 100644 --- a/spec/features/triggers_spec.rb +++ b/spec/features/triggers_spec.rb @@ -77,6 +77,53 @@ feature 'Triggers', feature: true, js: true do expect(page.find('.flash-notice')).to have_content 'Trigger was successfully updated.' expect(page.find('.triggers-list')).to have_content new_trigger_title end + + context 'scheduled triggers' do + let!(:trigger) do + create(:ci_trigger, owner: user, project: @project, description: trigger_title) + end + + context 'enabling schedule' do + before do + visit edit_namespace_project_trigger_path(@project.namespace, @project, trigger) + end + + scenario 'do fill form with valid data and save' do + find('#trigger_trigger_schedule_attributes_active').click + fill_in 'trigger_trigger_schedule_attributes_cron', with: '1 * * * *' + fill_in 'trigger_trigger_schedule_attributes_cron_timezone', with: 'UTC' + fill_in 'trigger_trigger_schedule_attributes_ref', with: 'master' + click_button 'Save trigger' + + expect(page.find('.flash-notice')).to have_content 'Trigger was successfully updated.' + end + + scenario 'do not fill form with valid data and save' do + find('#trigger_trigger_schedule_attributes_active').click + click_button 'Save trigger' + + expect(page).to have_content 'The form contains the following errors' + end + end + + context 'enabling schedule' do + before do + trigger.create_trigger_schedule(project: trigger.project, active: true) + + visit edit_namespace_project_trigger_path(@project.namespace, @project, trigger) + end + + scenario 'disable and save form' do + find('#trigger_trigger_schedule_attributes_active').click + click_button 'Save trigger' + expect(page.find('.flash-notice')).to have_content 'Trigger was successfully updated.' + + visit edit_namespace_project_trigger_path(@project.namespace, @project, trigger) + checkbox = find_field('trigger_trigger_schedule_attributes_active') + expect(checkbox).not_to be_checked + end + end + end end describe 'trigger "Take ownership" workflow' do @@ -125,14 +172,6 @@ feature 'Triggers', feature: true, js: true do describe 'show triggers workflow' do scenario 'contains trigger description placeholder' do expect(page.find('#trigger_description')['placeholder']).to eq 'Trigger description' - expect(page.find('#trigger_trigger_schedule_attributes_cron')['placeholder']).to eq '0 1 * * *' - expect(page.find('#trigger_trigger_schedule_attributes_cron_timezone')['placeholder']).to eq 'UTC' - expect(page.find('#trigger_ref')['placeholder']).to eq 'master' - end - - scenario 'show checkbox for registration of scheduled trigger and checked off defaultly' do - expect(page.find('#trigger_trigger_schedule_attributes__destroy')['type']).to eq 'checkbox' - expect(page.find('#trigger_trigger_schedule_attributes__destroy')['value']).to eq '0' end scenario 'show "legacy" badge for legacy trigger' do diff --git a/spec/workers/trigger_schedule_worker_spec.rb b/spec/workers/trigger_schedule_worker_spec.rb index 151e1c2f7b9..fdc638d9070 100644 --- a/spec/workers/trigger_schedule_worker_spec.rb +++ b/spec/workers/trigger_schedule_worker_spec.rb @@ -8,24 +8,39 @@ describe TriggerScheduleWorker do end context 'when there is a scheduled trigger within next_run_at' do + let(:next_run_at) { 2.days.ago } + + let!(:trigger_schedule) do + create(:ci_trigger_schedule, :nightly) + end + before do - trigger_schedule = create(:ci_trigger_schedule, :nightly) - time_future = Time.now + 10.days - allow(Time).to receive(:now).and_return(time_future) - @next_time = Gitlab::Ci::CronParser.new(trigger_schedule.cron, trigger_schedule.cron_timezone).next_time_from(time_future) + trigger_schedule.update_column(:next_run_at, next_run_at) end it 'creates a new trigger request' do - expect { worker.perform }.to change { Ci::TriggerRequest.count }.by(1) + expect { worker.perform }.to change { Ci::TriggerRequest.count } end it 'creates a new pipeline' do - expect { worker.perform }.to change { Ci::Pipeline.count }.by(1) + expect { worker.perform }.to change { Ci::Pipeline.count } expect(Ci::Pipeline.last).to be_pending end it 'updates next_run_at' do - expect { worker.perform }.to change { Ci::TriggerSchedule.last.next_run_at }.to(@next_time) + worker.perform + + expect(trigger_schedule.reload.next_run_at).not_to eq(next_run_at) + end + + context 'inactive schedule' do + before do + trigger_schedule.update(active: false) + end + + it 'does not create a new trigger' do + expect { worker.perform }.not_to change { Ci::TriggerRequest.count } + end end end @@ -42,10 +57,7 @@ describe TriggerScheduleWorker do end context 'when next_run_at is nil' do - before do - trigger_schedule = create(:ci_trigger_schedule, :nightly) - trigger_schedule.update_attribute(:next_run_at, nil) - end + let!(:trigger_schedule) { create(:ci_trigger_schedule, :nightly, next_run_at: nil) } it 'does not create a new pipeline' do expect { worker.perform }.not_to change { Ci::Pipeline.count } |