Browse Source

set correct LA for log based on year

pull/1402/head
Kat 3 years ago
parent
commit
5fa417bfc1
  1. 2
      app/models/lettings_log.rb
  2. 30
      spec/models/lettings_log_spec.rb

2
app/models/lettings_log.rb

@ -84,7 +84,7 @@ class LettingsLog < Log
def la def la
if location if location
location.location_code location.linked_local_authorities.active(startdate).first.code
else else
super super
end end

30
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(record_from_db["location_id"]).to eq(location.id)
expect(lettings_log["location_id"]).to eq(location.id) expect(lettings_log["location_id"]).to eq(location.id)
end 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 end
context "and not renewal" do context "and not renewal" do

Loading…
Cancel
Save