From 5fa417bfc120928a15eeecd4e583177eacb94532 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 10 Mar 2023 11:44:38 +0000 Subject: [PATCH] set correct LA for log based on year --- app/models/lettings_log.rb | 2 +- spec/models/lettings_log_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index dad1ef705..170280630 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -84,7 +84,7 @@ class LettingsLog < Log def la if location - location.location_code + location.linked_local_authorities.active(startdate).first.code else super end diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index c6f559aec..7290bc1f9 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -1870,6 +1870,36 @@ RSpec.describe LettingsLog do expect(record_from_db["location_id"]).to eq(location.id) expect(lettings_log["location_id"]).to eq(location.id) end + + context "and the location has multiple local authorities for different years" do + before do + LocalAuthorityLink.create!(local_authority_id: LocalAuthority.find_by(code: "E07000030").id, linked_local_authority_id: LocalAuthority.find_by(code: "E06000063").id) + location.update!(location_code: "E07000030") + Timecop.freeze(startdate) + lettings_log.update!(startdate:) + lettings_log.reload + end + + after { Timecop.unfreeze } + + context "with 22/23" do + let(:startdate) { Time.zone.local(2022, 4, 2) } + + it "returns the correct la" do + expect(lettings_log["location_id"]).to eq(location.id) + expect(lettings_log.la).to eq("E07000030") + end + end + + context "with 23/24" do + let(:startdate) { Time.zone.local(2023, 4, 2) } + + it "returns the correct la" do + expect(lettings_log["location_id"]).to eq(location.id) + expect(lettings_log.la).to eq("E06000063") + end + end + end end context "and not renewal" do