diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 112ab420f..a9cb49978 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -58,7 +58,6 @@ module DerivedVariables::LettingsLogVariables self.hhtype = household_type self.new_old = new_or_existing_tenant - self.vacdays = property_vacant_days if is_supported_housing? if location @@ -68,6 +67,7 @@ module DerivedVariables::LettingsLogVariables self.voiddate = startdate end end + self.vacdays = property_vacant_days set_housingneeds_fields if housingneeds? end diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 1ebf71b3d..217805339 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -1395,6 +1395,7 @@ RSpec.describe LettingsLog do renewal: 1, startdate: Time.zone.local(2021, 4, 10), created_at: Time.utc(2022, 2, 8, 16, 52, 15), + needstype: 2, }) end @@ -1431,6 +1432,12 @@ RSpec.describe LettingsLog do expect(record_from_db["referral"]).to eq(0) expect(lettings_log["referral"]).to eq(0) end + + it "correctly derives and saves vacdays" do + record_from_db = ActiveRecord::Base.connection.execute("select vacdays from lettings_logs where id=#{lettings_log.id}").to_a[0] + expect(record_from_db["vacdays"]).to eq(0) + expect(lettings_log["vacdays"]).to eq(0) + end end context "when answering the household characteristics questions" do