diff --git a/app/workers/retire_subject_worker.rb b/app/workers/retire_subject_worker.rb index 4906b5215..bc085009a 100644 --- a/app/workers/retire_subject_worker.rb +++ b/app/workers/retire_subject_worker.rb @@ -10,6 +10,9 @@ def perform(workflow_id, subject_ids, reason=nil) Array.wrap(subject_ids).each do |subject_id| count = subject_workflow_status(subject_id) RetirementWorker.perform_async(count.id, true, reason) + rescue ActiveRecord::RecordInvalid + # need to rescue the error when folks pass in a subject id that doesn't exist + # but we still keep processing the whole list of subjects we have end end end diff --git a/spec/workers/retire_subject_worker_spec.rb b/spec/workers/retire_subject_worker_spec.rb index 9246ec537..b9ca1f5de 100644 --- a/spec/workers/retire_subject_worker_spec.rb +++ b/spec/workers/retire_subject_worker_spec.rb @@ -12,10 +12,16 @@ let(:subject_ids) { [sms.subject_id, sms2.subject_id] } describe "#perform" do - it 'should handle an unknow workflow' do + it 'ignores an unknown workflow' do expect { worker.perform(-1, subject.id) }.not_to raise_error end + it 'ignores an unknown subject' do + allow(RetirementWorker).to receive(:perform_async) + worker.perform(workflow.id, [-1, subject.id]) + expect(RetirementWorker).to have_received(:perform_async).once + end + it 'should call the retirement worker with the subject workflow status resource' do expect(RetirementWorker) .to receive(:perform_async) @@ -41,21 +47,5 @@ expect(RetirementWorker).not_to receive(:perform_async) worker.perform(-1, subject.id) end - - describe "creating the sws resource" do - it 'should raise if there is a problem with the workflow' do - allow(worker).to receive(:workflow_exists?).and_return(true) - expect { - worker.perform(-1, subject.id) - }.to raise_error(ActiveRecord::RecordInvalid) - end - - it 'should raise if there is a problem with the subject' do - allow(worker).to receive(:workflow_exists?).and_return(true) - expect { - worker.perform(workflow.id, -1) - }.to raise_error(ActiveRecord::RecordInvalid) - end - end end end