Skip to content

Commit

Permalink
CLDC-3876: Household characteristic ecstat of child under 16 bug fix …
Browse files Browse the repository at this point in the history
…when age changed (#2959)

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

* Add tests
  • Loading branch information
Dinssa authored Feb 27, 2025
1 parent bb41465 commit fe89619
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/derived_variables/lettings_log_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def set_derived_fields!
self.beds = 1
end

clear_child_ecstat_for_age_changes!
child_under_16_constraints!

self.hhtype = household_type
Expand Down Expand Up @@ -243,6 +244,14 @@ def child_under_16_constraints!
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
return unless totelder && totadult && totchild

Expand Down
10 changes: 10 additions & 0 deletions app/models/derived_variables/sales_log_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def set_derived_fields!

if saledate && form.start_year_2024_or_later?
self.soctenant = soctenant_from_prevten_values
clear_child_ecstat_for_age_changes!
child_under_16_constraints!
end

Expand Down Expand Up @@ -181,6 +182,15 @@ def child_under_16_constraints!
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
return unless total_elder && total_adult && totchild

Expand Down
20 changes: 20 additions & 0 deletions spec/models/lettings_log_derived_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1206,4 +1206,24 @@
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
20 changes: 20 additions & 0 deletions spec/models/sales_log_derived_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@
expect { log.set_derived_fields! }.to change(log, :mortgage).from(50_000).to(nil)
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
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)
Expand Down

0 comments on commit fe89619

Please sign in to comment.