From 9c7105e764a14f156bfd05eccf84acfeb630a9ac Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 17 Oct 2024 15:39:32 +1100 Subject: [PATCH] Handle case of BackorderJob having no work --- app/jobs/backorder_job.rb | 2 ++ spec/jobs/backorder_job_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/app/jobs/backorder_job.rb b/app/jobs/backorder_job.rb index 174fe125ff..c8ce3f64a1 100644 --- a/app/jobs/backorder_job.rb +++ b/app/jobs/backorder_job.rb @@ -40,6 +40,8 @@ class BackorderJob < ApplicationJob user = order.distributor.owner items = backorderable_items(order) + return if items.empty? + # We are assuming that all variants are linked to the same wholesale # shop and its catalog: reference_link = items[0].variant.semantic_links[0].semantic_id diff --git a/spec/jobs/backorder_job_spec.rb b/spec/jobs/backorder_job_spec.rb index 301be0cd7f..79d2ec8846 100644 --- a/spec/jobs/backorder_job_spec.rb +++ b/spec/jobs/backorder_job_spec.rb @@ -104,6 +104,14 @@ RSpec.describe BackorderJob do # Clean up after ourselves: perform_enqueued_jobs(only: CompleteBackorderJob) end + + it "succeeds when no work to be done" do + # The database can change before the job is run. So maybe there's nothing + # to do. + expect { + subject.place_backorder(order) + }.not_to raise_error + end end describe "#place_order" do