summaryrefslogtreecommitdiff
path: root/spec/workers/pipeline_schedule_worker_spec.rb
blob: 91d5a16993fd2c32843c3c333ab69a54c32f89eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'spec_helper'

describe PipelineScheduleWorker do
  subject { described_class.new.perform }

  set(:project) { create(:project, :repository) }
  set(:user) { create(:user) }

  let!(:pipeline_schedule) do
    create(:ci_pipeline_schedule, :nightly, project: project, owner: user)
  end

  before do
    project.add_master(user)

    stub_ci_pipeline_to_return_yaml_file
  end

  context 'when there is a scheduled pipeline within next_run_at' do
    let(:next_run_at) { 2.days.ago }

    before do
      pipeline_schedule.update_column(:next_run_at, next_run_at)
    end

    it 'creates a new pipeline' do
      expect { subject }.to change { project.pipelines.count }.by(1)
    end

    it 'updates the next_run_at field' do
      subject

      expect(pipeline_schedule.reload.next_run_at).to be > Time.now
    end

    it 'sets the schedule on the pipeline' do
      subject
      expect(project.pipelines.last.pipeline_schedule).to eq(pipeline_schedule)
    end
  end

  context 'inactive schedule' do
    before do
      pipeline_schedule.update(active: false)
    end

    it 'does not creates a new pipeline' do
      expect { subject }.not_to change { project.pipelines.count }
    end
  end
end