Browse Source

Don't actually update the logs data when deactivating a location

pull/981/head
Kat 4 years ago
parent
commit
e2f9c3201c
  1. 1
      app/controllers/locations_controller.rb
  2. 12
      spec/requests/locations_controller_spec.rb

1
app/controllers/locations_controller.rb

@ -165,7 +165,6 @@ private
def confirm_deactivation def confirm_deactivation
if @location.update(deactivation_date: params[:location][:deactivation_date]) if @location.update(deactivation_date: params[:location][:deactivation_date])
@location.lettings_logs.filter_by_before_startdate( params[:location][:deactivation_date]).update(location: nil)
flash[:notice] = "#{@location.name || @location.postcode} has been deactivated" flash[:notice] = "#{@location.name || @location.postcode} has been deactivated"
end end
redirect_to scheme_location_path(@scheme, @location) redirect_to scheme_location_path(@scheme, @location)

12
spec/requests/locations_controller_spec.rb

@ -1239,8 +1239,6 @@ RSpec.describe LocationsController, type: :request do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:location) { FactoryBot.create(:location, scheme:) } let!(:location) { FactoryBot.create(:location, scheme:) }
let!(:lettings_log_to_deactivate) { FactoryBot.create(:lettings_log, scheme:, location:, startdate: Time.utc(2022, 10, 11) ) }
let!(:active_lettings_log) { FactoryBot.create(:lettings_log, scheme:, location:, startdate: Time.utc(2022, 10, 9) ) }
let(:startdate) { Time.utc(2021, 1, 2) } let(:startdate) { Time.utc(2021, 1, 2) }
let(:deactivation_date) { Time.utc(2022, 10, 10) } let(:deactivation_date) { Time.utc(2022, 10, 10) }
@ -1278,16 +1276,6 @@ RSpec.describe LocationsController, type: :request do
location.reload location.reload
expect(location.deactivation_date).to eq(deactivation_date) expect(location.deactivation_date).to eq(deactivation_date)
end end
it "updates lettings logs with a startdate later than deactivation_date" do
lettings_log_to_deactivate.reload
expect(lettings_log_to_deactivate.location).to eq(nil)
end
it "does not update lettings logs with a startdate earlier than deactivation_date" do
active_lettings_log.reload
expect(active_lettings_log.location).to eq(location)
end
end end
context "when the date is not selected" do context "when the date is not selected" do

Loading…
Cancel
Save