From 7bc4aab6ec100500f3143a5d6f90c5b93805afe3 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 22 Feb 2024 16:05:43 +0000 Subject: [PATCH] log updates logs and don't mark them unesolved --- .../update_schemes_from_csv_service.rb | 10 ++++++++-- .../update_schemes_and_locations_from_csv_spec.rb | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/services/bulk_update_from_csv/update_schemes_from_csv_service.rb b/app/services/bulk_update_from_csv/update_schemes_from_csv_service.rb index 4a2ef2c3b..92cddbfc9 100644 --- a/app/services/bulk_update_from_csv/update_schemes_from_csv_service.rb +++ b/app/services/bulk_update_from_csv/update_schemes_from_csv_service.rb @@ -93,8 +93,14 @@ private scheme["owning_organisation_id"] = organisation.id Rails.logger.info("Updating scheme #{original_attributes['scheme_code']} with owning_organisation: #{organisation.name}") editable_from_date = FormHandler.instance.earliest_open_for_editing_collection_start_date - LettingsLog.where(scheme_id: scheme.id).after_date(editable_from_date).update!(location: nil, scheme: nil, unresolved: true) - LettingsLog.where(scheme_id: scheme.id).where(startdate: nil).update!(location: nil, scheme: nil, unresolved: true) + + editable_logs_with_startdate = LettingsLog.where(scheme_id: scheme.id).after_date(editable_from_date) + editable_logs_with_startdate.update!(location: nil, scheme: nil) + Rails.logger.info("Updated logs with startdate for scheme S#{scheme.id}. Log IDs: #{editable_logs_with_startdate.map(&:id).join(', ')}") + + logs_without_start_date = LettingsLog.where(scheme_id: scheme.id).where(startdate: nil) + logs_without_start_date.update!(location: nil, scheme: nil) + Rails.logger.info("Updated logs without startdate for scheme S#{scheme.id}. Log IDs: #{logs_without_start_date.map(&:id).join(', ')}") end else Rails.logger.info("Cannot update scheme #{original_attributes['scheme_code']} with owning_organisation: #{value}. Organisation with name #{value} is not in the database or is not related to current organisation") diff --git a/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb b/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb index 2f981776e..8642f50a6 100644 --- a/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb +++ b/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb @@ -111,7 +111,6 @@ RSpec.describe "bulk_update" do lettings_log.reload expect(lettings_log.scheme).to be_nil expect(lettings_log.location).to be_nil - expect(lettings_log.unresolved).to eq(true) end it "does not update the scheme if it hasn't changed" do @@ -174,7 +173,6 @@ RSpec.describe "bulk_update" do lettings_log.reload expect(lettings_log.scheme).not_to be_nil expect(lettings_log.location).not_to be_nil - expect(lettings_log.unresolved).to be_falsey end it "only re-exports the logs for the schemes that have been updated" do @@ -206,6 +204,8 @@ RSpec.describe "bulk_update" do expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with service_name: Updated test name") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with sensitive: No") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with scheme_type: Direct Access Hostel") + expect(Rails.logger).to receive(:info).with("Updated logs with startdate for scheme S#{schemes[0].id}. Log IDs: ") + expect(Rails.logger).to receive(:info).with("Updated logs without startdate for scheme S#{schemes[0].id}. Log IDs: #{lettings_log.id}, #{lettings_log_4.id}, #{lettings_log_5.id}") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with arrangement_type: Another registered stock owner") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with primary_client_group: People with drug problems") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with has_other_client_group: No")