From eb5258b0c081ea3adaaa0c9279381c17e33eeb65 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Wed, 22 Mar 2023 11:40:44 +0000 Subject: [PATCH] prevent approve being called multiple times --- app/services/bulk_upload/processor.rb | 2 ++ spec/services/bulk_upload/processor_spec.rb | 22 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/services/bulk_upload/processor.rb b/app/services/bulk_upload/processor.rb index 3ba6fb4d8..af9d86dfb 100644 --- a/app/services/bulk_upload/processor.rb +++ b/app/services/bulk_upload/processor.rb @@ -34,6 +34,8 @@ class BulkUpload::Processor end def approve + return if bulk_upload.processed? + download create_logs ensure diff --git a/spec/services/bulk_upload/processor_spec.rb b/spec/services/bulk_upload/processor_spec.rb index edd049cd8..0c50ee8fd 100644 --- a/spec/services/bulk_upload/processor_spec.rb +++ b/spec/services/bulk_upload/processor_spec.rb @@ -243,4 +243,26 @@ RSpec.describe BulkUpload::Processor do end end end + + describe "#approve" do + let(:mock_creator) do + instance_double( + BulkUpload::Lettings::LogCreator, + call: nil, + path: nil, + ) + end + + context "when already processed" do + let(:bulk_upload) { create(:bulk_upload, :lettings, processed: true) } + + it "does not create logs again" do + allow(BulkUpload::Lettings::LogCreator).to receive(:new).with(bulk_upload:, path: nil).and_return(mock_creator) + + processor.approve + + expect(mock_creator).not_to have_received(:call) + end + end + end end