Browse Source

CLDC-3876: Household characteristic ecstat of child under 16 bug fix when age changed (#2959)

* Clear derived working situation of child under 16 when age is changed to 16 or above

* Add tests
update-status-at
Manny Dinssa 4 days ago committed by GitHub
parent
commit
fe89619b1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      app/models/derived_variables/lettings_log_variables.rb
  2. 10
      app/models/derived_variables/sales_log_variables.rb
  3. 20
      spec/models/lettings_log_derived_fields_spec.rb
  4. 20
      spec/models/sales_log_derived_fields_spec.rb

9
app/models/derived_variables/lettings_log_variables.rb

@ -72,6 +72,7 @@ module DerivedVariables::LettingsLogVariables
self.beds = 1 self.beds = 1
end end
clear_child_ecstat_for_age_changes!
child_under_16_constraints! child_under_16_constraints!
self.hhtype = household_type self.hhtype = household_type
@ -243,6 +244,14 @@ private
end end
end end
def clear_child_ecstat_for_age_changes!
(2..8).each do |idx|
if public_send("age#{idx}_changed?") && self["ecstat#{idx}"] == 9
self["ecstat#{idx}"] = nil
end
end
end
def household_type def household_type
return unless totelder && totadult && totchild return unless totelder && totadult && totchild

10
app/models/derived_variables/sales_log_variables.rb

@ -46,6 +46,7 @@ module DerivedVariables::SalesLogVariables
if saledate && form.start_year_2024_or_later? if saledate && form.start_year_2024_or_later?
self.soctenant = soctenant_from_prevten_values self.soctenant = soctenant_from_prevten_values
clear_child_ecstat_for_age_changes!
child_under_16_constraints! child_under_16_constraints!
end end
@ -181,6 +182,15 @@ private
end end
end end
def clear_child_ecstat_for_age_changes!
start_index = joint_purchase? ? 3 : 2
(start_index..6).each do |idx|
if public_send("age#{idx}_changed?") && self["ecstat#{idx}"] == 9
self["ecstat#{idx}"] = nil
end
end
end
def household_type def household_type
return unless total_elder && total_adult && totchild return unless total_elder && total_adult && totchild

20
spec/models/lettings_log_derived_fields_spec.rb

@ -1206,4 +1206,24 @@ RSpec.describe LettingsLog, type: :model do
end end
end end
end end
describe "#clear_child_ecstat_for_age_changes!" do
it "clears the working situation of a person that was previously a child under 16" do
log = create(:lettings_log, :completed, age2: 13)
log.age2 = 17
expect { log.set_derived_fields! }.to change(log, :ecstat2).from(9).to(nil)
end
it "does not clear the working situation of a person that had an age change but is still a child under 16" do
log = create(:lettings_log, :completed, age2: 13)
log.age2 = 15
expect { log.set_derived_fields! }.to not_change(log, :ecstat2)
end
it "does not clear the working situation of a person that had an age change but is still an adult" do
log = create(:lettings_log, :completed, age2: 45)
log.age2 = 46
expect { log.set_derived_fields! }.to not_change(log, :ecstat2)
end
end
end end

20
spec/models/sales_log_derived_fields_spec.rb

@ -78,6 +78,26 @@ RSpec.describe SalesLog, type: :model do
expect { log.set_derived_fields! }.to change(log, :mortgage).from(50_000).to(nil) expect { log.set_derived_fields! }.to change(log, :mortgage).from(50_000).to(nil)
end end
describe "#clear_child_ecstat_for_age_changes!" do
it "clears the working situation of a person that was previously a child under 16" do
log = create(:sales_log, :completed, age3: 13, age4: 16, age5: 45)
log.age3 = 17
expect { log.set_derived_fields! }.to change(log, :ecstat3).from(9).to(nil)
end
it "does not clear the working situation of a person that had an age change but is still a child under 16" do
log = create(:sales_log, :completed, age3: 13, age4: 16, age5: 45)
log.age3 = 15
expect { log.set_derived_fields! }.to not_change(log, :ecstat3)
end
it "does not clear the working situation of a person that had an age change but is still an adult" do
log = create(:sales_log, :completed, age3: 13, age4: 16, age5: 45)
log.age5 = 46
expect { log.set_derived_fields! }.to not_change(log, :ecstat5)
end
end
context "with a log that is not outright sales" do context "with a log that is not outright sales" do
it "does not derive deposit when mortgage used is no" do it "does not derive deposit when mortgage used is no" do
log = build(:sales_log, :shared_ownership_setup_complete, value: 123_400, deposit: nil, mortgageused: 2) log = build(:sales_log, :shared_ownership_setup_complete, value: 123_400, deposit: nil, mortgageused: 2)

Loading…
Cancel
Save