diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 7a9bf6344..16d16bed0 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -253,6 +253,7 @@ private 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 end def process_postcode_changes! diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index baf63b4da..7e7d23705 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1160,6 +1160,7 @@ RSpec.describe CaseLog do managing_organisation: organisation, owning_organisation: organisation, renewal: "Yes", + year: 2021, }) end @@ -1168,6 +1169,12 @@ RSpec.describe CaseLog do 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 end end