From f22662770c3ca66f96f71cbe453387be0d8e5f99 Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 15 Nov 2022 16:52:50 +0000 Subject: [PATCH] Update scheme --- app/controllers/locations_controller.rb | 2 +- spec/requests/locations_controller_spec.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 15ba38d25..da0c58d3f 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -190,7 +190,7 @@ private end def update_affected_logs - @location.lettings_logs.filter_by_before_startdate(params[:location][:deactivation_date]).update!(location: nil) + @location.lettings_logs.filter_by_before_startdate(params[:location][:deactivation_date]).update!(location: nil, scheme: nil) end def deactivation_date diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 16bd4f8b2..b2a2c9237 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1240,7 +1240,7 @@ RSpec.describe LocationsController, type: :request do let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:location) { FactoryBot.create(:location, scheme:) } let(:deactivation_date) { Time.utc(2022, 10, 10) } - let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, location:, tenancylength: nil, startdate:) } + let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) } let(:startdate) { Time.utc(2022, 10, 11) } before do @@ -1290,8 +1290,10 @@ RSpec.describe LocationsController, type: :request do context "and a log startdate is after location deactivation date" do it "clears the location and scheme answers" do expect(lettings_log.location).to eq(location) + expect(lettings_log.scheme).to eq(scheme) lettings_log.reload expect(lettings_log.location).to eq(nil) + expect(lettings_log.scheme).to eq(nil) end end @@ -1300,8 +1302,10 @@ RSpec.describe LocationsController, type: :request do it "does not update the log" do expect(lettings_log.location).to eq(location) + expect(lettings_log.scheme).to eq(scheme) lettings_log.reload expect(lettings_log.location).to eq(location) + expect(lettings_log.scheme).to eq(scheme) end end end