From 898e36c184f5bd3fcd40a96d9ecf191cd753f111 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 25 Nov 2022 10:24:16 +0000 Subject: [PATCH] Mark log as impacted by deactivation when location is deactivated --- app/controllers/locations_controller.rb | 2 +- ...1125102013_add_impacted_by_deactivation_column.rb | 7 +++++++ db/schema.rb | 1 + spec/requests/locations_controller_spec.rb | 12 ++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20221125102013_add_impacted_by_deactivation_column.rb diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 1da3bf5c4..551241d01 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -219,7 +219,7 @@ private end def reset_location_and_scheme_for_logs! - @location.lettings_logs.filter_by_before_startdate(params[:deactivation_date].to_time).update!(location: nil, scheme: nil) + @location.lettings_logs.filter_by_before_startdate(params[:deactivation_date].to_time).update!(location: nil, scheme: nil, impacted_by_deactivation: true) end def toggle_date(key) diff --git a/db/migrate/20221125102013_add_impacted_by_deactivation_column.rb b/db/migrate/20221125102013_add_impacted_by_deactivation_column.rb new file mode 100644 index 000000000..3be527a13 --- /dev/null +++ b/db/migrate/20221125102013_add_impacted_by_deactivation_column.rb @@ -0,0 +1,7 @@ +class AddImpactedByDeactivationColumn < ActiveRecord::Migration[7.0] + def change + change_table :lettings_logs, bulk: true do |t| + t.column :impacted_by_deactivation, :boolean + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e5a4d27e4..8c5463a37 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -237,6 +237,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_25_142847) do t.integer "void_date_value_check" t.integer "housingneeds_type" t.integer "housingneeds_other" + t.boolean "impacted_by_deactivation" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id" t.index ["location_id"], name: "index_lettings_logs_on_location_id" t.index ["managing_organisation_id"], name: "index_lettings_logs_on_managing_organisation_id" diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 45463ceb1..3c9164e32 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1364,6 +1364,12 @@ RSpec.describe LocationsController, type: :request do expect(lettings_log.location).to eq(nil) expect(lettings_log.scheme).to eq(nil) end + + it "marks log as needing attention" do + expect(lettings_log.impacted_by_deactivation).to eq(nil) + lettings_log.reload + expect(lettings_log.impacted_by_deactivation).to eq(true) + end end context "and a log startdate is before location deactivation date" do @@ -1376,6 +1382,12 @@ RSpec.describe LocationsController, type: :request do expect(lettings_log.location).to eq(location) expect(lettings_log.scheme).to eq(scheme) end + + it "does not mark log as needing attention" do + expect(lettings_log.impacted_by_deactivation).to eq(nil) + lettings_log.reload + expect(lettings_log.impacted_by_deactivation).to eq(nil) + end end end