From 4df960e6784df8d5212f701cc9fc6c8916d36914 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 28 Feb 2024 11:53:53 +0000 Subject: [PATCH] Log updates before clearing locations and schemes --- .../update_locations_from_csv_service.rb | 6 +++--- .../update_schemes_from_csv_service.rb | 4 ++-- .../update_schemes_and_locations_from_csv_spec.rb | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/services/bulk_update_from_csv/update_locations_from_csv_service.rb b/app/services/bulk_update_from_csv/update_locations_from_csv_service.rb index 748199c8c..4a2577fc3 100644 --- a/app/services/bulk_update_from_csv/update_locations_from_csv_service.rb +++ b/app/services/bulk_update_from_csv/update_locations_from_csv_service.rb @@ -112,17 +112,17 @@ private Rails.logger.info("Updating location #{original_attributes['location_code']} with scheme: S#{scheme.id}") editable_from_date = FormHandler.instance.earliest_open_for_editing_collection_start_date editable_logs = LettingsLog.where(location_id: location.id).after_date(editable_from_date) + Rails.logger.info("Clearing location and scheme for logs with startdate and location #{location.id}. Log IDs: #{editable_logs.map(&:id).join(', ')}") editable_logs.update!(location: nil, scheme: nil, values_updated_at: Time.zone.now) - Rails.logger.info("Cleared location and scheme for logs with startdate and location #{location.id}. Log IDs: #{editable_logs.map(&:id).join(', ')}") logs_without_start_date = LettingsLog.where(scheme_id: scheme.id).where(startdate: nil) + Rails.logger.info("Clearing location and scheme for logs without startdate and location #{location.id}. Log IDs: #{logs_without_start_date.map(&:id).join(', ')}") logs_without_start_date.update!(location: nil, scheme: nil, values_updated_at: Time.zone.now) - Rails.logger.info("Cleared location and scheme for logs without startdate and location #{location.id}. Log IDs: #{logs_without_start_date.map(&:id).join(', ')}") exportable_from_date = FormHandler.instance.previous_collection_start_date remaining_logs_to_export = LettingsLog.where(location_id: location.id).after_date(exportable_from_date) + Rails.logger.info("Clearing location and scheme for non editable logs with location #{location.id}. Log IDs: #{remaining_logs_to_export.map(&:id).join(', ')}") remaining_logs_to_export.update_all(location_id: nil, scheme_id: nil, values_updated_at: Time.zone.now) - Rails.logger.info("Cleared location and scheme for non editable logs with location #{location.id}. Log IDs: #{remaining_logs_to_export.map(&:id).join(', ')}") end else Rails.logger.info("Cannot update location #{original_attributes['location_code']} with scheme_code: #{value}. Scheme with id #{value} is not in the database") 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 4017cd6fe..bb4a0c261 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 @@ -95,12 +95,12 @@ private editable_from_date = FormHandler.instance.earliest_open_for_editing_collection_start_date editable_logs_with_startdate = LettingsLog.where(scheme_id: scheme.id).after_date(editable_from_date) + Rails.logger.info("Clearing location and scheme for logs with startdate and scheme S#{scheme.id}. Log IDs: #{editable_logs_with_startdate.map(&:id).join(', ')}") editable_logs_with_startdate.update!(location: nil, scheme: nil) - Rails.logger.info("Cleared location and scheme for logs with startdate and 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) + Rails.logger.info("Clearing location and scheme for logs without startdate and scheme S#{scheme.id}. Log IDs: #{logs_without_start_date.map(&:id).join(', ')}") logs_without_start_date.update!(location: nil, scheme: nil) - Rails.logger.info("Cleared location and scheme for logs without startdate and 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 9d10e9524..50dd98400 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 @@ -204,8 +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("Cleared location and scheme for logs with startdate and scheme S#{schemes[0].id}. Log IDs: ") - expect(Rails.logger).to receive(:info).with("Cleared location and scheme for logs without startdate and 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("Clearing location and scheme for logs with startdate and scheme S#{schemes[0].id}. Log IDs: ") + expect(Rails.logger).to receive(:info).with("Clearing location and scheme for logs without startdate and 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") @@ -424,9 +424,9 @@ RSpec.describe "bulk_update" do lettings_log_5.save!(validate: false) expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with scheme: S#{different_scheme.id}") - expect(Rails.logger).to receive(:info).with("Cleared location and scheme for logs with startdate and location #{locations[0].id}. Log IDs: #{lettings_log.id}") - expect(Rails.logger).to receive(:info).with("Cleared location and scheme for logs without startdate and location #{locations[0].id}. Log IDs: ") - expect(Rails.logger).to receive(:info).with("Cleared location and scheme for non editable logs with location #{locations[0].id}. Log IDs: ") + expect(Rails.logger).to receive(:info).with("Clearing location and scheme for logs with startdate and location #{locations[0].id}. Log IDs: #{lettings_log.id}") + expect(Rails.logger).to receive(:info).with("Clearing location and scheme for logs without startdate and location #{locations[0].id}. Log IDs: ") + expect(Rails.logger).to receive(:info).with("Clearing location and scheme for non editable logs with location #{locations[0].id}. Log IDs: #{lettings_log_4.id}") expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with postcode: B11BB") expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with name: Updated name") expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with location_code: E09000033")