Browse Source

Correctly set the log status, remove redundant confirm_soft_validations

pull/1615/head
Kat 3 years ago
parent
commit
66a0d323e9
  1. 2
      app/models/bulk_upload.rb
  2. 3
      app/services/bulk_upload/lettings/log_creator.rb
  3. 5
      app/services/bulk_upload/processor.rb
  4. 3
      app/services/bulk_upload/sales/log_creator.rb
  5. 9
      spec/services/bulk_upload/lettings/log_creator_spec.rb
  6. 8
      spec/services/bulk_upload/processor_spec.rb

2
app/models/bulk_upload.rb

@ -74,8 +74,6 @@ class BulkUpload < ApplicationRecord
def unpend_and_confirm_soft_validations
logs.find_each do |log|
log.skip_update_status = true
log.status = log.status_cache
log.retirement_value_check = 0
log.pregnancy_value_check = 0
log.major_repairs_date_value_check = 0

3
app/services/bulk_upload/lettings/log_creator.rb

@ -1,10 +1,9 @@
class BulkUpload::Lettings::LogCreator
attr_reader :bulk_upload, :path
def initialize(bulk_upload:, path:, confirm_soft_validations: false)
def initialize(bulk_upload:, path:)
@bulk_upload = bulk_upload
@path = path
@confirm_soft_validations = confirm_soft_validations
end
def call

5
app/services/bulk_upload/processor.rb

@ -17,7 +17,7 @@ class BulkUpload::Processor
elsif validator.create_logs?
create_logs
if validator.soft_validation_errors_only?
send_check_soft_validations_mail
elsif created_logs_but_incompleted?
@ -94,11 +94,10 @@ private
bulk_upload.user
end
def create_logs(confirm_soft_validations: false)
def create_logs
log_creator_class.new(
bulk_upload:,
path: downloader.path,
confirm_soft_validations:,
).call
end

3
app/services/bulk_upload/sales/log_creator.rb

@ -1,10 +1,9 @@
class BulkUpload::Sales::LogCreator
attr_reader :bulk_upload, :path
def initialize(bulk_upload:, path:, confirm_soft_validations: false)
def initialize(bulk_upload:, path:)
@bulk_upload = bulk_upload
@path = path
@confirm_soft_validations = confirm_soft_validations
end
def call

9
spec/services/bulk_upload/lettings/log_creator_spec.rb

@ -164,6 +164,15 @@ RSpec.describe BulkUpload::Lettings::LogCreator do
service.call
expect(LettingsLog.last.status).to eql("pending")
end
it "does not set unanswered soft validations" do
service.call
log = LettingsLog.last
expect(log.age1).to be(22)
expect(log.ecstat1).to be(5)
expect(log.retirement_value_check).to be(nil)
end
end
context "when valid csv with existing log" do

8
spec/services/bulk_upload/processor_spec.rb

@ -235,14 +235,14 @@ RSpec.describe BulkUpload::Processor do
expect(mail_double).to have_received(:deliver_later)
end
it "calls log creator without the confirm_soft_validations option" do
it "calls log creator" do
log_creator_double = instance_double(BulkUpload::Lettings::LogCreator, call: nil)
allow(BulkUpload::Lettings::LogCreator).to receive(:new).and_return(log_creator_double)
processor.call
expect(BulkUpload::Lettings::LogCreator).to have_received(:new).with(bulk_upload:, path:, confirm_soft_validations: false)
expect(BulkUpload::Lettings::LogCreator).to have_received(:new).with(bulk_upload:, path:)
end
end
@ -313,14 +313,14 @@ RSpec.describe BulkUpload::Processor do
expect(mail_double).to have_received(:deliver_later)
end
it "calls log creator with the confirm_soft_validations option" do
it "calls log creator" do
log_creator_double = instance_double(BulkUpload::Lettings::LogCreator, call: nil)
allow(BulkUpload::Lettings::LogCreator).to receive(:new).and_return(log_creator_double)
processor.call
expect(BulkUpload::Lettings::LogCreator).to have_received(:new).with(bulk_upload:, path:, confirm_soft_validations: true)
expect(BulkUpload::Lettings::LogCreator).to have_received(:new).with(bulk_upload:, path:)
end
end

Loading…
Cancel
Save