@ -268,13 +268,6 @@ RSpec.describe LettingsLog do 
			
		
	
		
		
			
				
					
					      expect ( record_from_db [ " mrcdate " ] . year ) . to  eq ( 2021 )        expect ( record_from_db [ " mrcdate " ] . year ) . to  eq ( 2021 )   
			
		
	
		
		
			
				
					
					    end      end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    it  " correctly derives and saves partial and full major property void date "  do   
			
		
	
		
		
			
				
					
					      record_from_db  =  ActiveRecord :: Base . connection . execute ( " select voiddate from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					      expect ( record_from_db [ " voiddate " ] . day ) . to  eq ( 3 )   
			
		
	
		
		
			
				
					
					      expect ( record_from_db [ " voiddate " ] . month ) . to  eq ( 3 )   
			
		
	
		
		
			
				
					
					      expect ( record_from_db [ " voiddate " ] . year ) . to  eq ( 2021 )   
			
		
	
		
		
			
				
					
					    end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    it  " correctly derives and saves incref "  do      it  " correctly derives and saves incref "  do   
			
		
	
		
		
			
				
					
					      record_from_db  =  ActiveRecord :: Base . connection . execute ( " select incref from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select incref from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					      expect ( record_from_db [ " incref " ] ) . to  eq ( 1 )        expect ( record_from_db [ " incref " ] ) . to  eq ( 1 )   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -1504,334 +1497,329 @@ RSpec.describe LettingsLog do 
			
		
	
		
		
			
				
					
					      expect ( record_from_db [ " has_benefits " ] ) . to  eq ( 1 )        expect ( record_from_db [ " has_benefits " ] ) . to  eq ( 1 )   
			
		
	
		
		
			
				
					
					    end      end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    context  " when it is a renewal "  do      context  " when updating values that derive vacdays "  do   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					      let ( :lettings_log )  {  create ( :lettings_log ,  startdate : )  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      context  " when start date is set "  do   
			
		
	
		
		
			
				
					
					        let ( :startdate )  {  Time . zone . now  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        it  " correctly derives vacdays when voiddate is set "  do   
			
		
	
		
		
			
				
					
					          day_count  =  3   
			
		
	
		
		
			
				
					
					          expect  {  lettings_log . update! ( voiddate :  startdate  -  day_count . days )  } . to  change ( lettings_log ,  :vacdays ) . to  day_count   
			
		
	
		
		
			
				
					
					          expect  {  lettings_log . update! ( voiddate :  nil )  } . to  change ( lettings_log ,  :vacdays ) . from ( day_count ) . to  nil   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        it  " correctly derives vacdays when mrcdate is set "  do   
			
		
	
		
		
			
				
					
					          day_count  =  3   
			
		
	
		
		
			
				
					
					          expect  {  lettings_log . update! ( mrcdate :  startdate  -  day_count . days )  } . to  change ( lettings_log ,  :vacdays ) . to  day_count   
			
		
	
		
		
			
				
					
					          expect  {  lettings_log . update! ( mrcdate :  nil )  } . to  change ( lettings_log ,  :vacdays ) . from ( day_count ) . to  nil   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      context  " when start date is not set "  do   
			
		
	
		
		
			
				
					
					        let ( :startdate )  {  nil  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        it  " correctly derives vacdays when voiddate is set "  do   
			
		
	
		
		
			
				
					
					          day_count  =  3   
			
		
	
		
		
			
				
					
					          lettings_log . update! ( voiddate :  Time . zone . now  -  day_count . days )   
			
		
	
		
		
			
				
					
					          expect ( lettings_log . vacdays ) . to  be  nil   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        it  " correctly derives vacdays when mrcdate is set "  do   
			
		
	
		
		
			
				
					
					          day_count  =  3   
			
		
	
		
		
			
				
					
					          lettings_log . update! ( mrcdate :  Time . zone . now  -  day_count . days )   
			
		
	
		
		
			
				
					
					          expect ( lettings_log . vacdays ) . to  be  nil   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					    end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    context  " when updating renewal "  do   
			
		
	
		
		
			
				
					
					      let! ( :lettings_log )  do        let! ( :lettings_log )  do   
			
		
	
		
		
			
				
					
					        described_class . create ( {          described_class . create ( {   
			
		
	
		
		
			
				
					
					          managing_organisation :  owning_organisation ,            managing_organisation :  owning_organisation ,   
			
		
	
		
		
			
				
					
					          owning_organisation : ,            owning_organisation : ,   
			
		
	
		
		
			
				
					
					          created_by :  created_by_user ,            created_by :  created_by_user ,   
			
		
	
		
		
			
				
					
					          renewal :  1 ,   
			
		
	
		
		
			
				
					
					          startdate :  Time . zone . local ( 2021 ,  4 ,  10 ) ,            startdate :  Time . zone . local ( 2021 ,  4 ,  10 ) ,   
			
		
	
		
		
			
				
					
					          created_at :  Time . utc ( 2022 ,  2 ,  8 ,  16 ,  52 ,  15 ) ,            created_at :  Time . utc ( 2022 ,  2 ,  8 ,  16 ,  52 ,  15 ) ,   
			
		
	
		
		
			
				
					
					        } )          } )   
			
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " correctly derives and saves waityear "  do        it  " correctly derives the length of time on local authority waiting list "  do   
			
				
				
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select waityear from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]          expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :waityear ) . to  2   
			
				
				
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " waityear " ] ) . to  eq ( 2 )          expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :waityear ) . from ( 2 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " waityear " ] ) . to  eq ( 2 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " correctly derives and saves underoccupation_benefitcap if year is 2021 "  do        it  " correctly derives the number of times previously offered since becoming available "  do   
			
				
				
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select underoccupation_benefitcap from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]          expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :offered ) . to  0   
			
				
				
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " underoccupation_benefitcap " ] ) . to  eq ( 2 )          expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :offered ) . from ( 0 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " underoccupation_benefitcap " ] ) . to  eq ( 2 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " correctly derives and saves prevten "  do        it  " correctly derives referral if the letting is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					        lettings_log . managing_organisation . update! ( {  provider_type :  " PRP "  } )          expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :referral ) . to  1   
			
				
				
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  needstype :  1  } )          expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :referral ) . from ( 1 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					
      end   
			
				
				
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select prevten from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " prevten " ] ) . to  eq ( 32 )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " prevten " ] ) . to  eq ( 32 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        lettings_log . managing_organisation . update! ( {  provider_type :  " LA "  } )        it  " correctly derives voiddate if the letting is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  needstype :  1  } )          expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :voiddate ) . to  lettings_log . startdate   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					        expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :voiddate ) . from ( lettings_log . startdate ) . to  nil   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select prevten from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]        it  " correctly derives first_time_property_let_as_social_housing and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " prevten " ] ) . to  eq ( 30 )          expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :first_time_property_let_as_social_housing ) . to  0    
			
				
				
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " prevten " ] ) . to  eq ( 30 )          expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :first_time_property_let_as_social_housing ) . from ( 0 ) . to  nil    
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " correctly derives and saves referral "  do        it  " correctly derives vacancy reason and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select referral from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]          expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :rsnvac ) . to  14   
			
				
				
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " referral " ] ) . to  eq ( 1 )          expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :rsnvac ) . from ( 14 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " referral " ] ) . to  eq ( 1 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " correctly derives and saves vacdays "  do        it  " derives vacdays as 0 if log is renewal "  do   
			
				
				
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select vacdays from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]          expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :vacdays ) . to  0   
			
				
				
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " vacdays " ] ) . to  eq ( 0 )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " vacdays " ] ) . to  eq ( 0 )   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " correctly derives and saves first_time_property_let_as_social_housing "  do        it  " correctly derives underoccupation_benefitcap if log is a renewal from 2021/22 "  do   
			
				
				
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute (          lettings_log . update! ( renewal :  1 )   
			
				
				
			
		
	
		
		
			
				
					
					          " select first_time_property_let_as_social_housing "  \          expect ( lettings_log . underoccupation_benefitcap ) . to  be  2   
			
				
				
			
		
	
		
		
			
				
					
					          "  from lettings_logs where id= #{ lettings_log . id } " ,   
			
		
	
		
		
			
				
					
					        ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " first_time_property_let_as_social_housing " ] ) . to  eq ( 0 )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " first_time_property_let_as_social_housing " ] ) . to  eq ( 0 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " derives vacancy reason as relet "  do        it  " clears underoccupation_benefitcap if log is no longer a renewal "  do   
			
				
				
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select rsnvac from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]          expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :underoccupation_benefitcap ) . to  2   
			
				
				
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " rsnvac " ] ) . to  eq ( 14 )          expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :underoccupation_benefitcap ) . from ( 2 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " rsnvac " ] ) . to  eq ( 14 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      context  " when deriving renttype and unitletas "  do        it  " clears underoccupation_benefitcap if log is no longer in 2021/22 "  do   
			
				
				
			
		
	
		
		
			
				
					
					        before  do          expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :underoccupation_benefitcap ) . to  2   
			
				
				
			
		
	
		
		
			
				
					
					          Timecop . freeze ( Time . zone . local ( 2022 ,  1 ,  1 ) )          Timecop . return   
			
				
				
			
		
	
		
		
			
				
					
					          allow ( FeatureToggle ) . to  receive ( :startdate_two_week_validation_enabled? ) . and_return ( false )          expect  {  lettings_log . update! ( startdate :  Time . zone . local ( 2023 ,  1 ,  1 ) )  } . to  change ( lettings_log ,  :underoccupation_benefitcap ) . from ( 2 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					          lettings_log . update! ( rent_type : ,  irproduct_other :  " other " )        end   
			
				
				
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        after  do        context  " when the log is general needs "  do   
			
				
				
			
		
	
		
		
			
				
					
					          Timecop . unfreeze          context  " and the managing organisation is a private registered provider "  do   
			
				
				
			
		
	
		
		
			
				
					
					        end            before  do   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					            lettings_log . managing_organisation . update! ( provider_type :  " PRP " )   
			
		
	
		
		
			
				
					
					            lettings_log . update! ( needstype :  1 ,  renewal :  1 )   
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        context  " when the rent_type is Social Rent (0) "  do            it  " correctly derives prevten "  do   
			
				
				
			
		
	
		
		
			
				
					
					          let ( :rent_type )  {  0  }              expect ( lettings_log . prevten ) . to  be  32   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves renttype and unitletas as Social rent(1) "  do            it  " clears prevten if the log is marked as supported housing "  do   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select renttype from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]              lettings_log . update! ( needstype :  2 )   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . renttype ) . to  eq ( 1 )              expect ( lettings_log . prevten ) . to  be  nil   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " renttype " ] ) . to  eq ( 1 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves unitletas as Social rent(1) "  do            it  " clears prevten if renewal is update to no "  do   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]              lettings_log . update! ( renewal :  0 )   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . unitletas ) . to  eq ( 1 )              expect ( lettings_log . prevten ) . to  be  nil   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " unitletas " ] ) . to  eq ( 1 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          context  " and it is a 23/24 form "  do          context  " and the managing organisation is a local authority "  do   
			
				
				
			
		
	
		
		
			
				
					
					            before  do            before  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )              lettings_log . managing_organisation . update! ( provider_type :  " LA " )   
			
				
				
			
		
	
		
		
			
				
					
					            end              lettings_log . update! ( needstype :  1 ,  renewal :  1 )   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            after   do            it  " correctly derives prevten " do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . unfreeze               expect ( lettings_log . prevten ) . to  be  30   
			
				
				
			
		
	
		
		
			
				
					
					             end            end   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            around  do  | example |            it  " clears prevten if the log is marked as supported housing "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )  do              expect  {  lettings_log . update! ( needstype :  2 )  } . to  change ( lettings_log ,  :prevten ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					                Singleton . __init__ ( FormHandler )            end   
			
				
				
			
		
	
		
		
			
				
					
					                example . run   
			
		
	
		
		
			
				
					
					              end   
			
		
	
		
		
			
				
					
					              Timecop . return   
			
		
	
		
		
			
				
					
					              Singleton . __init__ ( FormHandler )   
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            it  " derives and saves unitletas as Social rent(1) "  do            it  " clears prevten if renewal is update to no "  do   
			
				
				
			
		
	
		
		
			
				
					
					              lettings_log . update! ( startdate :  Time . zone . local ( 2023 ,  5 ,  1 ) )              expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :prevten ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					              record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					              expect ( lettings_log . unitletas ) . to  eq ( 1 )   
			
		
	
		
		
			
				
					
					              expect ( record_from_db [ " unitletas " ] ) . to  eq ( 1 )   
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					        end          end   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					         context  " when the rent_type is Affordable Rent(1) "  do        context  " and updating rent_type "  do   
			
				
				
			
		
	
		
		
			
				
					
					           let ( :rent_type )  {  1   }          let ( :irproduct_other )  {  nil   }   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves renttype as Affordable Rent(2) "  do          around  do  | example |   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select renttype from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]            Timecop . freeze ( now )  do   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . renttype ) . to  eq ( 2 )              Singleton . __init__ ( FormHandler )   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " renttype " ] ) . to  eq ( 2 )              lettings_log . update! ( rent_type : ,  irproduct_other : ,  startdate :  now )   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					            example . run   
			
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves unitletas as Affordable Rent(2) "  do          context  " when collection year is 2022/23 or earlier "  do   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]            let ( :now )  {  Time . zone . local ( 2023 ,  1 ,  1 )  }   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . unitletas ) . to  eq ( 2 )   
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " unitletas " ] ) . to  eq ( 2 )   
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          context  " and it is a 23/24 form "  do            context  " when rent_type is Social Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					            before  do              let ( :rent_type )  {  0  }   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )   
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            after  do              it  " derives the most recent let type as Social Rent basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . unfreeze                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  1   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					              expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 1 ) . to  nil   
			
		
	
		
		
			
				
					
					            end              end   
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            around  do  | example |            context  " when rent_type is Affordable Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )  do              let ( :rent_type )  {  1  }   
			
				
				
			
		
	
		
		
			
				
					
					                Singleton . __init__ ( FormHandler )   
			
		
	
		
		
			
				
					
					                example . run   
			
		
	
		
		
			
				
					
					              end   
			
		
	
		
		
			
				
					
					              Timecop . return   
			
		
	
		
		
			
				
					
					              Singleton . __init__ ( FormHandler )   
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            it  " derives and saves unitletas as Affordable Rent basis(2) "  do              it  " derives the most recent let type as Affordable Rent basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					              lettings_log . update! ( startdate :  Time . zone . local ( 2023 ,  5 ,  1 ) )                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  2   
			
				
				
			
		
	
		
		
			
				
					
					              record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]                expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 2 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					              expect ( lettings_log . unitletas ) . to  eq ( 2 )   
			
		
	
		
		
			
				
					
					              expect ( record_from_db [ " unitletas " ] ) . to  eq ( 2 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					            end              end   
			
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        context  " when the  rent_type is London Affordable Rent(2)  "  do             context  " when rent_type is London Affordable Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					          let ( :rent_type )  {  2  }               let ( :rent_type )  {  2  }   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves renttype as London Affordable Rent(2)  "  do               it  " derives the most recent let type as Affordable Rent basis if it is a renewal and clears it if it is not  "  do   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select renttype from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  2    
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . renttype ) . to  eq ( 2 )                expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from  ( 2 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " renttype " ] ) . to  eq ( 2 )              end   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves unitletas as London Affordable Rent(2) "  do            context  " when rent_type is Rent to Buy "  do   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]              let ( :rent_type )  {  3  }   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . unitletas ) . to  eq ( 2 )   
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " unitletas " ] ) . to  eq ( 2 )   
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          context  " and it is a 23/24 form "  do              it  " derives the most recent let type as Intermediate Rent basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					            before  do                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  4   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )                expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 4 ) . to  nil   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					            end              end   
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            after  do            context  " when rent_type is London Living Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . unfreeze              let ( :rent_type )  {  4  }   
			
				
				
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            around  do  | example |              it  " derives the most recent let type as Intermediate Rent basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )  do                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  4   
			
				
				
			
		
	
		
		
			
				
					
					                Singleton . __init__ ( FormHandler )                expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 4 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					                example . run   
			
		
	
		
		
			
				
					
					              end   
			
		
	
		
		
			
				
					
					              Timecop . return   
			
		
	
		
		
			
				
					
					              Singleton . __init__ ( FormHandler )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					            end              end   
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          context  " when rent_type is Other intermediate rent product "  do   
			
		
	
		
		
			
				
					
					            let ( :rent_type )  {  5  }   
			
		
	
		
		
			
				
					
					            let ( :irproduct_other )  {  " Rent first "  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            it  " derives and saves unitletas as London Affordable Rent basis(5) "  do              it  " derives the most recent let type as Intermediate Rent basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					              lettings_log . update! ( startdate :  Time . zone . local ( 2023 ,  5 ,  1 ) )                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  4   
			
				
				
			
		
	
		
		
			
				
					
					              record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]                expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 4 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					              expect ( lettings_log . unitletas ) . to  eq ( 5 )   
			
		
	
		
		
			
				
					
					              expect ( record_from_db [ " unitletas " ] ) . to  eq ( 5 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					            end              end   
			
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					        end          end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        context  " when the rent_type is Rent to Buy(3)  "  do          context  " when collection year is 2023/24 or later  "  do   
			
				
				
			
		
	
		
		
			
				
					
					          let ( :rent_type )  {  3   }            let ( :now )  {  Time . zone . local ( 2024 ,  1 ,  1 )   }   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves renttype as Intermediate Rent(3) "  do            context  " when rent_type is Social Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select renttype from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]              let ( :rent_type )  {  0  }   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . renttype ) . to  eq ( 3 )   
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " renttype " ] ) . to  eq ( 3 )   
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves unitletas as Intermediate Rent(4)  "  do              it  " derives the most recent let type as Social Rent basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  1   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . unitletas ) . to  eq ( 4 )                expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 1 ) . to  nil    
			
				
				
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " unitletas " ] ) . to  eq ( 4 )              end   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          context  " and it is a 23/24 form "  do            context  " when rent_type is Affordable Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					            before  do              let ( :rent_type )  {  1  }   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )   
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            after  do              it  " derives the most recent let type as Affordable Rent basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . unfreeze                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  2   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					              expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 2 ) . to  nil   
			
		
	
		
		
			
				
					
					            end              end   
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            around  do  | example |            context  " when rent_type is London Affordable Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )  do              let ( :rent_type )  {  2  }   
			
				
				
			
		
	
		
		
			
				
					
					                Singleton . __init__ ( FormHandler )   
			
		
	
		
		
			
				
					
					                example . run   
			
		
	
		
		
			
				
					
					              end   
			
		
	
		
		
			
				
					
					              Timecop . return   
			
		
	
		
		
			
				
					
					              Singleton . __init__ ( FormHandler )   
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            it  " derives and saves unitletas as Rent to Buy basis(6) "  do              it  " derives the most recent let type as London Affordable Rent basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					              lettings_log . update! ( startdate :  Time . zone . local ( 2023 ,  5 ,  1 ) )                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  5   
			
				
				
			
		
	
		
		
			
				
					
					              record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]                expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 5 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					              expect ( lettings_log . unitletas ) . to  eq ( 6 )   
			
		
	
		
		
			
				
					
					              expect ( record_from_db [ " unitletas " ] ) . to  eq ( 6 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					            end              end   
			
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        context  " when the rent_type is London Living Rent(4)  "  do             context  " when rent_type is Rent to Buy  "  do   
			
				
				
			
		
	
		
		
			
				
					
					          let ( :rent_type )  {  4 }               let ( :rent_type )  {  3 }   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves renttype as Intermediate Rent(3) "  do              it  " derives the most recent let type as Rent to Buy basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select renttype from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  6   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . renttype ) . to  eq ( 3 )                expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 6 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " renttype " ] ) . to  eq ( 3 )              end   
			
				
				
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves unitletas as Intermediate Rent(4) "  do   
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					            expect ( lettings_log . unitletas ) . to  eq ( 4 )   
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " unitletas " ] ) . to  eq ( 4 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          context  " and it is a 23/24 form "  do            context  " when rent_type is London Living Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					            before  do              let ( :rent_type )  {  4  }   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )   
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            after  do              it  " derives the most recent let type as London Living Rent basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . unfreeze                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  7   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					              expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 7 ) . to  nil   
			
		
	
		
		
			
				
					
					            end              end   
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            around  do  | example |            context  " when rent_type is Other intermediate rent product "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )  do              let ( :rent_type )  {  5  }   
			
				
				
			
		
	
		
		
			
				
					
					                Singleton . __init__ ( FormHandler )              let ( :irproduct_other )  {  " Rent first "  }   
			
				
				
			
		
	
		
		
			
				
					
					                example . run   
			
		
	
		
		
			
				
					
					              end   
			
		
	
		
		
			
				
					
					              Timecop . return   
			
		
	
		
		
			
				
					
					              Singleton . __init__ ( FormHandler )   
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            it  " derives and saves unitletas as London Living Rent basis(7) "  do              it  " derives the most recent let type as Another Intermediate Rent basis if it is a renewal and clears it if it is not "  do   
			
				
				
			
		
	
		
		
			
				
					
					              lettings_log . update! ( startdate :  Time . zone . local ( 2023 ,  5 ,  1 ) )                expect  {  lettings_log . update! ( renewal :  1 )  } . to  change ( lettings_log ,  :unitletas ) . to  8   
			
				
				
			
		
	
		
		
			
				
					
					              record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]                expect  {  lettings_log . update! ( renewal :  0 )  } . to  change ( lettings_log ,  :unitletas ) . from ( 8 ) . to  nil   
			
				
				
			
		
	
		
		
			
				
					
					              expect ( lettings_log . unitletas ) . to  eq ( 7 )   
			
		
	
		
		
			
				
					
					              expect ( record_from_db [ " unitletas " ] ) . to  eq ( 7 )   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					            end              end   
			
		
	
		
		
			
				
					
					          end            end   
			
		
	
		
		
			
				
					
					        end          end   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					    end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    context  " when updating rent type "  do   
			
		
	
		
		
			
				
					
					      let ( :irproduct_other )  {  nil  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      before  do   
			
		
	
		
		
			
				
					
					        lettings_log . update! ( rent_type : ,  irproduct_other : )   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      context  " when rent_type is Social Rent "  do   
			
		
	
		
		
			
				
					
					        let ( :rent_type )  {  0  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        it  " derives renttype as Social Rent "  do   
			
		
	
		
		
			
				
					
					          expect ( lettings_log . renttype ) . to  be  1   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        context  " when the rent_type is Other intermediate rent product(5) "  do        context  " when rent_type is Affordable Rent  "  do   
			
				
				
			
		
	
		
		
			
				
					
					          let ( :rent_type )  {  5  }          let ( :rent_type )  {  1 }   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves renttype as Intermediate Rent(3) "  do          it  " derives renttype as Affordable Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select renttype from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]            expect ( lettings_log . renttype ) . to  be  2   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . renttype ) . to  eq ( 3 )          end   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " renttype " ] ) . to  eq ( 3 )        end   
			
				
				
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          it  " derives and saves unitletas as Intermediate Rent(4) "  do        context  " when rent_type is London Affordable Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					            record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]          let ( :rent_type )  {  2  }   
			
				
				
			
		
	
		
		
			
				
					
					            expect ( lettings_log . unitletas ) . to  eq ( 4 )   
			
		
	
		
		
			
				
					
					            expect ( record_from_db [ " unitletas " ] ) . to  eq ( 4 )   
			
		
	
		
		
			
				
					
					          end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          context  " and it is a 23/24 form "  do          it  " derives renttype as Affordable Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					            before  do             expect ( lettings_log . renttype ) . to  be  2   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )           end   
			
				
				
			
		
	
		
		
			
				
					
					             end        end   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            after  do        context  " when rent_type is Rent to Buy "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . unfreeze          let ( :rent_type )  {  3  }   
			
				
				
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            around  do  | example |          it  " derives renttype as Intermediate Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					              Timecop . freeze ( Time . zone . local ( 2023 ,  5 ,  1 ) )  do            expect ( lettings_log . renttype ) . to  be  3   
			
				
				
			
		
	
		
		
			
				
					
					                Singleton . __init__ ( FormHandler )          end   
			
				
				
			
		
	
		
		
			
				
					
					                example . run        end   
			
				
				
			
		
	
		
		
			
				
					
					              end   
			
		
	
		
		
			
				
					
					              Timecop . return   
			
		
	
		
		
			
				
					
					              Singleton . __init__ ( FormHandler )   
			
		
	
		
		
			
				
					
					            end   
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					            it  " derives and saves unitletas as Other intermediate rent basis(8) "  do        context  " when rent_type is London Living Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					              lettings_log . update! ( startdate :  Time . zone . local ( 2023 ,  5 ,  1 ) )          let ( :rent_type )  {  4  }   
			
				
				
			
		
	
		
		
			
				
					
					              record_from_db  =  ActiveRecord :: Base . connection . execute ( " select unitletas from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]  
 
			
				
				
			
		
	
		
		
			
				
					
					              expect ( lettings_log . unitletas ) . to  eq ( 8 )          it  " derives renttype as Intermediate Rent "  do   
			
				
				
			
		
	
		
		
			
				
					
					              expect ( record_from_db [ " unitletas " ] ) . to  eq ( 8 )            expect ( lettings_log . renttype ) . to  be  3   
			
				
				
			
		
	
		
		
			
				
					
					            end          end   
			
				
				
			
		
	
		
		
			
				
					
					          end        end   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      context  " when rent_type is Other intermediate rent product "  do   
			
		
	
		
		
			
				
					
					        let ( :rent_type )  {  5  }   
			
		
	
		
		
			
				
					
					        let ( :irproduct_other )  {  " Rent first "  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        it  " derives renttype as Intermediate Rent "  do   
			
		
	
		
		
			
				
					
					          expect ( lettings_log . renttype ) . to  be  3   
			
		
	
		
		
			
				
					
					        end          end   
			
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					    end      end   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -2168,37 +2156,6 @@ RSpec.describe LettingsLog do 
			
		
	
		
		
			
				
					
					          expect ( record_from_db [ " wchair " ] ) . to  eq ( 1 )            expect ( record_from_db [ " wchair " ] ) . to  eq ( 1 )   
			
		
	
		
		
			
				
					
					        end          end   
			
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      context  " and renewal "  do   
			
		
	
		
		
			
				
					
					        before  do   
			
		
	
		
		
			
				
					
					          Timecop . freeze ( Time . zone . local ( 2022 ,  4 ,  2 ) )   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        after  do   
			
		
	
		
		
			
				
					
					          Timecop . unfreeze   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        let ( :scheme )  {  create ( :scheme )  }   
			
		
	
		
		
			
				
					
					        let ( :location )  {  create ( :location ,  scheme : )  }   
			
		
	
		
		
			
				
					
					        let! ( :supported_housing_lettings_log )  do   
			
		
	
		
		
			
				
					
					          described_class . create! ( {   
			
		
	
		
		
			
				
					
					            managing_organisation :  owning_organisation ,   
			
		
	
		
		
			
				
					
					            owning_organisation : ,   
			
		
	
		
		
			
				
					
					            created_by :  created_by_user ,   
			
		
	
		
		
			
				
					
					            needstype :  2 ,   
			
		
	
		
		
			
				
					
					            scheme_id :  scheme . id ,   
			
		
	
		
		
			
				
					
					            location_id :  location . id ,   
			
		
	
		
		
			
				
					
					            renewal :  1 ,   
			
		
	
		
		
			
				
					
					            startdate :  Time . zone . local ( 2022 ,  4 ,  2 ) ,   
			
		
	
		
		
			
				
					
					            created_at :  Time . utc ( 2022 ,  2 ,  8 ,  16 ,  52 ,  15 ) ,   
			
		
	
		
		
			
				
					
					          } )   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        it  " correctly infers and saves the renewal date "  do   
			
		
	
		
		
			
				
					
					          record_from_db  =  ActiveRecord :: Base . connection . execute ( " SELECT voiddate from lettings_logs where id= #{ supported_housing_lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					          expect ( record_from_db [ " voiddate " ] . to_i ) . to  eq ( supported_housing_lettings_log . startdate . to_i )   
			
		
	
		
		
			
				
					
					        end   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					    end      end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    context  " when saving accessibility needs "  do      context  " when saving accessibility needs "  do   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -2434,77 +2391,18 @@ RSpec.describe LettingsLog do 
			
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					    end      end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    context  " when it changes from a renewal to not a renewal "  do   
			
		
	
		
		
			
				
					
					      let ( :lettings_log )  {  create ( :lettings_log )  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " resets inferred waityear value "  do   
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  renewal :  1  } )   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select waityear from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " waityear " ] ) . to  eq ( 2 )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " waityear " ] ) . to  eq ( 2 )   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  renewal :  0  } )   
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select waityear from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " waityear " ] ) . to  eq ( nil )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " waityear " ] ) . to  eq ( nil )   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " resets inferred vacancy reason value "  do   
			
		
	
		
		
			
				
					
					        vacancy_reason  =  " rsnvac "   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  renewal :  1  } )   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select  #{ vacancy_reason }  from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ vacancy_reason ] ) . to  eq ( 14 )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ vacancy_reason ] ) . to  eq ( 14 )   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  renewal :  0  } )   
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select  #{ vacancy_reason }  from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ vacancy_reason ] ) . to  eq ( nil )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ vacancy_reason ] ) . to  eq ( nil )   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					    end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    context  " when it changes from a supported housing to not a supported housing "  do      context  " when it changes from a supported housing to not a supported housing "  do   
			
		
	
		
		
			
				
					
					      let ( :location )  {  create ( :location ,  mobility_type :  " A " ,  postcode :  " SW1P 4DG " )  }        let ( :location )  {  create ( :location ,  mobility_type :  " A " ,  postcode :  " SW1P 4DG " )  }   
			
		
	
		
		
			
				
					
					      let ( :lettings_log )  {  create ( :lettings_log ,  location : )  }        let ( :lettings_log )  {  create ( :lettings_log ,  location : )  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " resets inferred wchair value "  do        it  " resets inferred wchair value "  do   
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  needstype :  2  } )          expect  {  lettings_log . update! ( needstype :  2 )  } . to  change ( lettings_log ,  :wchair ) . to ( 2 )   
			
				
				
			
		
	
		
		
			
				
					
					
        expect  {  lettings_log . update! ( needstype :  1 )  } . to  change ( lettings_log ,  :wchair ) . from ( 2 ) . to ( nil )   
			
				
				
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select wchair from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " wchair " ] ) . to  eq ( 2 )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " wchair " ] ) . to  eq ( 2 )   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  needstype :  1  } )   
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select needstype from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " wchair " ] ) . to  eq ( nil )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " wchair " ] ) . to  eq ( nil )   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " resets location "  do        it  " resets location "  do   
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  needstype :  2  } )          lettings_log . update! ( needstype :  2 )   
			
				
				
			
		
	
		
		
			
				
					
					
        expect  {  lettings_log . update! ( needstype :  1 )  } . to  change ( lettings_log ,  :location_id ) . from ( location . id ) . to ( nil )   
			
				
				
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select location_id from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " location_id " ] ) . to  eq ( location . id )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " location_id " ] ) . to  eq ( location . id )   
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  needstype :  1  } )   
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select location_id from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " location_id " ] ) . to  eq ( nil )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " location_id " ] ) . to  eq ( nil )   
			
		
	
		
		
			
				
					
					      end   
			
		
	
		
		
			
				
					
					    end   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    context  " when it is not a renewal "  do   
			
		
	
		
		
			
				
					
					      let ( :lettings_log )  {  create ( :lettings_log )  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      it  " saves waityear value "  do   
			
		
	
		
		
			
				
					
					        lettings_log . update! ( {  renewal :  0 ,  waityear :  2  } )   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        record_from_db  =  ActiveRecord :: Base . connection . execute ( " select waityear from lettings_logs where id= #{ lettings_log . id } " ) . to_a [ 0 ]   
			
		
	
		
		
			
				
					
					        expect ( record_from_db [ " waityear " ] ) . to  eq ( 2 )   
			
		
	
		
		
			
				
					
					        expect ( lettings_log [ " waityear " ] ) . to  eq ( 2 )   
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					      end        end   
			
		
	
		
		
			
				
					
					    end      end