spec/gush/job_spec.rb in gush-3.0.0 vs spec/gush/job_spec.rb in gush-4.0.0

- old
+ new

@@ -47,10 +47,49 @@ expect(job.enqueued?).to eq(true) expect(job.running?).to eq(false) end end + describe "#enqueue_worker!" do + it "enqueues the job using Gush::Worker" do + job = described_class.new(name: "a-job", workflow_id: 123) + + expect { + job.enqueue_worker! + }.to change{ActiveJob::Base.queue_adapter.enqueued_jobs.size}.from(0).to(1) + end + + it "handles ActiveJob.set options" do + freeze_time = Time.utc(2023, 01, 21, 14, 36, 0) + + travel_to freeze_time do + job = described_class.new(name: "a-job", workflow_id: 123) + job.enqueue_worker!(wait_until: freeze_time + 5.minutes) + expect(Gush::Worker).to have_a_job_enqueued_at(123, job_with_id(job.class.name), 5.minutes) + end + end + end + + describe "#worker_options" do + it "returns a blank options hash by default" do + job = described_class.new + expect(job.worker_options).to eq({}) + end + + it "returns a hash with the queue setting" do + job = described_class.new + job.queue = 'my-queue' + expect(job.worker_options).to eq({ queue: 'my-queue' }) + end + + it "returns a hash with the wait setting" do + job = described_class.new + job.wait = 123 + expect(job.worker_options).to eq({ wait: 123 }) + end + end + describe "#start!" do it "resets flags and marks as running" do job = described_class.new(name: "a-job") job.enqueue! @@ -68,11 +107,17 @@ end describe "#as_json" do context "finished and enqueued set to true" do it "returns correct hash" do - job = described_class.new(workflow_id: 123, id: "702bced5-bb72-4bba-8f6f-15a3afa358bd", finished_at: 123, enqueued_at: 120) + job = described_class.new( + workflow_id: 123, + id: '702bced5-bb72-4bba-8f6f-15a3afa358bd', + finished_at: 123, + enqueued_at: 120, + wait: 300 + ) expected = { id: '702bced5-bb72-4bba-8f6f-15a3afa358bd', klass: "Gush::Job", incoming: [], outgoing: [], @@ -81,10 +126,11 @@ finished_at: 123, enqueued_at: 120, params: {}, queue: nil, output_payload: nil, - workflow_id: 123 + workflow_id: 123, + wait: 300 } expect(job.as_json).to eq(expected) end end end