Sha256: b63e989a7be268dda6fbafe728454280c6ce9a84890aa62c38bd7c67bd1f9550

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

module Marty
  describe Jobs::Schedule do
    let!(:schedule) do
      Marty::BackgroundJob::Schedule.create!(
        job_class: 'TestJob',
        arguments: [],
        cron: '0 0 * * *',
        state: 'on'
      )
    end

    it 'schedules jobs' do
      expect(TestJob.scheduled?(schedule_id: schedule.id)).to be false
      described_class.call
      expect(TestJob.scheduled?(schedule_id: schedule.id)).to be true
    end

    it 'deletes previously scheduled jobs' do
      described_class.call
      expect(TestJob.scheduled?(schedule_id: schedule.id)).to be true
      schedule.destroy!

      non_cron_job = Delayed::Job.create!(handler: 'Non cron job')

      dj = Delayed::Job.last
      dj.handler = dj.handler.gsub('TestJob', 'WrongTestJob')
      dj.save!

      described_class.call

      expect(TestJob.scheduled?(schedule_id: schedule.id)).to be false
      any_old_scheduled_jobs = Delayed::Job.where('handler ILIKE ?', '%WrongTestJob%').any?
      expect(any_old_scheduled_jobs).to be false

      non_cron_job = Delayed::Job.find_by(handler: 'Non cron job')
      expect(non_cron_job).to be_present
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
marty-14.3.0 spec/services/jobs/schedule_spec.rb
marty-14.0.0 spec/services/jobs/schedule_spec.rb
marty-13.0.2 spec/services/jobs/schedule_spec.rb
marty-11.0.0 spec/services/jobs/schedule_spec.rb
marty-10.0.3 spec/services/jobs/schedule_spec.rb
marty-10.0.2 spec/services/jobs/schedule_spec.rb
marty-10.0.0 spec/services/jobs/schedule_spec.rb