From 7a77016760924fba3a0290ec8f4b4cf8bade57ff Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 16 Jan 2024 14:29:56 +0000 Subject: [PATCH] Update logs --- .../update_schemes_from_csv_service.rb | 1 + ...ate_schemes_and_locations_from_csv_spec.rb | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) 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 e33e0640d..5aaa03956 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 @@ -89,6 +89,7 @@ private if organisation.present? && (organisation.child_organisations.include?(current_organisation) || organisation.parent_organisations.include?(current_organisation)) scheme["owning_organisation_id"] = organisation.id Rails.logger.info("Updating scheme #{original_attributes['scheme_code']} with owning_organisation: #{organisation.name}") + LettingsLog.where(scheme_id: scheme.id).update!(location: nil, scheme: nil, unresolved: true) 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") end 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 3a4eb6274..c7e532368 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 @@ -101,6 +101,17 @@ RSpec.describe "bulk_update" do expect(schemes[0].total_units).to eq(2) end + it "updates the lettings log if scheme has changes owning organisation" do + create(:organisation_relationship, parent_organisation: schemes[0].owning_organisation, child_organisation: different_organisation) + + task.invoke(original_schemes_csv_path, updated_schemes_csv_path) + + 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 task.invoke(original_schemes_csv_path, updated_schemes_csv_path) schemes[1].reload @@ -143,6 +154,15 @@ RSpec.describe "bulk_update" do expect(schemes[0].owning_organisation).not_to eq(different_organisation) end + it "does not update the lettings log if scheme owning organisation didn't change" do + task.invoke(original_schemes_csv_path, updated_schemes_csv_path) + + 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 task.invoke(original_schemes_csv_path, updated_schemes_csv_path)