From 9f52ca6eeff92234902b45e9a91943ac23b68b3a Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 4 Aug 2022 12:27:18 +0100 Subject: [PATCH] Reset wchair when needstype changes from supported housing to not supported housing Co-authored-by: James Rose --- app/models/case_log.rb | 3 ++- spec/models/case_log_spec.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 0e9d550e0..35594bb39 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -536,7 +536,8 @@ private dependent_questions = { waityear: [{ key: :renewal, value: 0 }], homeless: [{ key: :renewal, value: 0 }], referral: [{ key: :renewal, value: 0 }], - underoccupation_benefitcap: [{ key: :renewal, value: 0 }] } + underoccupation_benefitcap: [{ key: :renewal, value: 0 }], + wchair: [{ key: :needstype, value: 1 }] } dependent_questions.each do |dependent, conditions| condition_key = conditions.first[:key] diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 712e1eddf..0df6361f5 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1842,6 +1842,24 @@ RSpec.describe CaseLog do end end + context "when it changes from a supported housing to not a supported housing" do + let(:location) { FactoryBot.create(:location, mobility_type: "A") } + let(:case_log) { FactoryBot.create(:case_log, location:) } + + it "resets inferred wchair value" do + case_log.update!({ needstype: 2 }) + + record_from_db = ActiveRecord::Base.connection.execute("select wchair from case_logs where id=#{case_log.id}").to_a[0] + expect(record_from_db["wchair"]).to eq(2) + expect(case_log["wchair"]).to eq(2) + + case_log.update!({ needstype: 1 }) + record_from_db = ActiveRecord::Base.connection.execute("select needstype from case_logs where id=#{case_log.id}").to_a[0] + expect(record_from_db["wchair"]).to eq(nil) + expect(case_log["wchair"]).to eq(nil) + end + end + context "when it is not a renewal" do let(:case_log) { FactoryBot.create(:case_log) }