Browse Source

Renewal inferred variables (#285)

* Infer layear if it is a renewal

* Infer underoccupation_benefitcap if it is a renewal

* Infer homelessness if it is a renewal
pull/288/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
f0f5070135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/models/case_log.rb
  2. 7
      spec/fixtures/complete_case_log.json
  3. 29
      spec/models/case_log_spec.rb

3
app/models/case_log.rb

@ -252,6 +252,9 @@ private
self.tcharge = brent.to_f + scharge.to_f + pscharge.to_f + supcharg.to_f
self.has_benefits = get_has_benefits
self.nocharge = household_charge == "Yes" ? "No" : "Yes"
self.layear = "Less than 1 year" if renewal == "Yes"
self.underoccupation_benefitcap = "No" if renewal == "Yes" && year == 2021
self.homeless = "No" if renewal == "Yes"
end
def process_postcode_changes!

7
spec/fixtures/complete_case_log.json vendored

@ -40,7 +40,7 @@
"age8": 2,
"sex8": "Prefer not to say",
"ecstat8": "Child under 16",
"homeless": "Yes - other homelessness",
"homeless": "No",
"reason": 1,
"underoccupation_benefitcap": "No",
"leftreg": "No - they left up to 5 years ago",
@ -90,8 +90,7 @@
"lawaitlist": "Less than 1 year",
"prevloc": "Ashford",
"previous_postcode": "SE2 6RT",
"reasonpref": "Yes",
"reasonable_preference_reason": "dummy",
"reasonpref": "No",
"cbl": "Yes",
"chr": "Yes",
"cap": "No",
@ -116,7 +115,7 @@
"illness_type_9": "No",
"illness_type_10": "No",
"condition_effects_prefer_not_to_say": "Yes",
"rp_homeless": "Yes",
"rp_homeless": "No",
"rp_insan_unsat": "No",
"rp_medwel": "No",
"rp_hardship": "No",

29
spec/models/case_log_spec.rb

@ -1153,6 +1153,35 @@ RSpec.describe CaseLog do
record_from_db = ActiveRecord::Base.connection.execute("select has_benefits from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["has_benefits"]).to eq("Yes")
end
context "when it is a renewal" do
let!(:case_log) do
described_class.create({
managing_organisation: organisation,
owning_organisation: organisation,
renewal: "Yes",
year: 2021,
})
end
it "correctly derives and saves layear" do
record_from_db = ActiveRecord::Base.connection.execute("select layear from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["layear"]).to eq(2)
expect(case_log["layear"]).to eq("Less than 1 year")
end
it "correctly derives and saves underoccupation_benefitcap if year is 2021" do
record_from_db = ActiveRecord::Base.connection.execute("select underoccupation_benefitcap from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["underoccupation_benefitcap"]).to eq(2)
expect(case_log["underoccupation_benefitcap"]).to eq("No")
end
it "correctly derives and saves homeless" do
record_from_db = ActiveRecord::Base.connection.execute("select homeless from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["homeless"]).to eq(1)
expect(case_log["homeless"]).to eq("No")
end
end
end
describe "resetting invalidated fields" do

Loading…
Cancel
Save