From 65c4eb90bb18881124b119f9ec724c2e551b3b96 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 29 Nov 2023 11:24:34 +0000 Subject: [PATCH] Do not reset created by for merged orgs --- app/models/lettings_log.rb | 1 + spec/requests/form_controller_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 5bd06c972..a38f1eba1 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -559,6 +559,7 @@ class LettingsLog < Log return unless updated_by&.support? return if owning_organisation.blank? || managing_organisation.blank? || created_by.blank? return if created_by&.organisation == managing_organisation || created_by&.organisation == owning_organisation + return if created_by&.organisation == owning_organisation.absorbing_organisation || created_by&.organisation == managing_organisation.absorbing_organisation update!(created_by: nil) end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index fbe3dbb1d..0c19414fe 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -214,6 +214,33 @@ RSpec.describe FormController, type: :request do end end + context "with valid absorbed managing organisation" do + let(:params) do + { + id: lettings_log.id, + lettings_log: { + page: "stock_owner", + owning_organisation_id: stock_owner.id, + }, + } + end + let(:merged_org) { create(:organisation) } + + before do + merged_org.update!(merge_date: Time.zone.today, absorbing_organisation: organisation) + lettings_log.update!(owning_organisation: merged_org, created_by: user, managing_organisation: merged_org) + lettings_log.reload + end + + it "does not reset created by" do + post "/lettings-logs/#{lettings_log.id}/stock-owner", params: params + expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}/managing-organisation") + follow_redirect! + lettings_log.reload + expect(lettings_log.created_by).to eq(user) + end + end + context "with only adding the stock owner" do let(:params) do {