Sha256: e4a8cb976d46e762b8c972bf7c2bf293e4dc7a6c358f96a3148774c8363e76db

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe Delayed::Heartbeat::DeleteWorkerResults do
  let(:worker) { create_worker(name: 'my-worker') }
  let(:job) { create_job(locked_by: worker.name) }
  let(:results) { create_results(worker => [job]) }

  describe "#workers" do
    specify { expect(results.workers).to eq [worker] }
  end

  describe "#unlocked_jobs" do
    let(:other_worker) { create_worker(name: 'my-other-worker') }
    let(:other_job) { create_job(locked_by: worker.name) }
    let(:results) { create_results(worker => [job], other_worker => [other_job]) }

    specify { expect(results.unlocked_jobs(worker)).to eq [job] }
    specify { expect(results.unlocked_jobs).to match_array [job, other_job] }
  end

  describe "#to_s" do
    it "includes workers" do
      results = create_results(worker => [])
      expect(results.to_s).to include(worker.name)
    end

    it "includes jobs for workers" do
      expect(results.to_s).to include(job.id.to_s)
    end
  end

  def create_worker(attributes = {})
    Delayed::Heartbeat::Worker.create!(attributes)
  end

  def create_job(attributes = {})
    attributes = attributes.reverse_merge(payload_object: TestJob.new)
    Delayed::Job.create!(attributes)
  end

  def create_results(worker_job_map)
    Delayed::Heartbeat::DeleteWorkerResults.new(worker_job_map)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
delayed_job_heartbeat_plugin-0.2.0 spec/delayed/heartbeat/delete_worker_results_spec.rb