From daed805f4f4395c4e50cb78323ee00608a3eb092 Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Wed, 12 Jun 2024 09:13:31 +0100 Subject: [PATCH] ensure the correct number of beds is calculated if the log is for a bedsit and the beds attribute has been temporarily cleared --- app/models/lettings_log.rb | 4 +++- spec/models/lettings_log_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index cc67a6ae2..d1fc1f7f0 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -533,7 +533,9 @@ class LettingsLog < Log def beds_for_la_rent_range return 0 if is_supported_housing? - beds.nil? ? nil : [beds, LaRentRange::MAX_BEDS].min + real_beds = beds || (1 if is_bedsit?) + + real_beds.nil? ? nil : [real_beds, LaRentRange::MAX_BEDS].min end def soft_min_for_period diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 2f4576719..53ff1be54 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -1834,6 +1834,14 @@ RSpec.describe LettingsLog do expect(lettings_log.beds_for_la_rent_range).to eq(4) end end + + context "when the log is for a bedsit, beds is not routed to and is not yet re-derived" do + let(:lettings_log) { build(:lettings_log, unittype_gn: 2, beds: nil) } + + it "returns 1" do + expect(lettings_log.beds_for_la_rent_range).to eq(1) + end + end end describe "#collection_period_open?" do