Browse Source

Update logs

pull/2144/head
Kat 2 years ago
parent
commit
7a77016760
  1. 1
      app/services/bulk_update_from_csv/update_schemes_from_csv_service.rb
  2. 20
      spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

1
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

20
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)

Loading…
Cancel
Save