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