Browse Source

change field names to lowercase and fix the tests

pull/79/head
Kat 4 years ago
parent
commit
5469399095
  1. 28
      app/models/case_log.rb
  2. 14
      app/validations/financial_validations.rb
  3. 54
      app/validations/household_validations.rb
  4. 4
      app/validations/property_validations.rb
  5. 12
      app/validations/tenancy_validations.rb
  6. 296
      config/forms/2021_2022.json
  7. 178
      db/migrate/20211101192151_rename_fields.rb
  8. 180
      db/schema.rb
  9. 625
      docs/api/DLUHC-CORE-Data.v1.json
  10. 58
      spec/controllers/case_logs_controller_spec.rb
  11. 2
      spec/factories/case_log.rb
  12. 131
      spec/features/case_log_spec.rb
  13. 231
      spec/fixtures/complete_case_log.json
  14. 122
      spec/fixtures/forms/test_form.json
  15. 36
      spec/helpers/check_answers_helper_spec.rb
  16. 4
      spec/helpers/conditional_questions_helper_spec.rb
  17. 12
      spec/helpers/question_attribute_helper_spec.rb
  18. 2
      spec/helpers/tasklist_helper_spec.rb
  19. 146
      spec/models/case_log_spec.rb
  20. 2
      spec/models/form_spec.rb
  21. 20
      spec/requests/case_log_controller_spec.rb

28
app/models/case_log.rb

@ -66,20 +66,20 @@ class CaseLog < ApplicationRecord
end
def weekly_net_income
case net_income_frequency
case incfreq
when "Weekly"
net_income
earnings
when "Monthly"
((net_income * 12) / 52.0).round(0)
((earnings * 12) / 52.0).round(0)
when "Yearly"
(net_income / 12.0).round(0)
(earnings / 12.0).round(0)
end
end
def applicable_income_range
return unless person_1_economic_status
return unless ecstat1
IncomeRange::ALLOWED[person_1_economic_status.to_sym]
IncomeRange::ALLOWED[ecstat1.to_sym]
end
private
@ -111,25 +111,25 @@ private
dynamically_not_required << "other_reason_for_leaving_last_settled_home"
end
if net_income.to_i.zero?
dynamically_not_required << "net_income_frequency"
if earnings.to_i.zero?
dynamically_not_required << "incfreq"
end
if tenancy_type == "Fixed term – Secure"
dynamically_not_required << "fixed_term_tenancy"
if tenancy == "Fixed term – Secure"
dynamically_not_required << "tenancylength"
end
unless net_income_in_soft_max_range? || net_income_in_soft_min_range?
dynamically_not_required << "override_net_income_validation"
end
unless tenancy_type == "Other"
dynamically_not_required << "other_tenancy_type"
unless tenancy == "Other"
dynamically_not_required << "tenancyother"
end
unless net_income_known == "Yes"
dynamically_not_required << "net_income"
dynamically_not_required << "net_income_frequency"
dynamically_not_required << "earnings"
dynamically_not_required << "incfreq"
end
start_range = (household_number_of_other_members || 0) + 2

14
app/validations/financial_validations.rb

@ -13,25 +13,25 @@ module FinancialValidations
EMPLOYED_STATUSES = ["Full-time - 30 hours or more", "Part-time - Less than 30 hours"].freeze
def validate_net_income_uc_proportion(record)
(1..8).any? do |n|
economic_status = record["person_#{n}_economic_status"]
economic_status = record["ecstat#{n}"]
is_employed = EMPLOYED_STATUSES.include?(economic_status)
relationship = record["person_#{n}_relationship"]
relationship = record["relat#{n}"]
is_partner_or_main = relationship == "Partner" || (relationship.nil? && economic_status.present?)
if is_employed && is_partner_or_main && record.net_income_uc_proportion == "All"
record.errors.add :net_income_uc_proportion, "income is from Universal Credit, state pensions or benefits cannot be All if the tenant or the partner works part or full time"
if is_employed && is_partner_or_main && record.benefits == "All"
record.errors.add :benefits, "income is from Universal Credit, state pensions or benefits cannot be All if the tenant or the partner works part or full time"
end
end
end
def validate_net_income(record)
return unless record.person_1_economic_status && record.weekly_net_income
return unless record.ecstat1 && record.weekly_net_income
if record.weekly_net_income > record.applicable_income_range.hard_max
record.errors.add :net_income, "Net income cannot be greater than #{record.applicable_income_range.hard_max} given the tenant's working situation"
record.errors.add :earnings, "Net income cannot be greater than #{record.applicable_income_range.hard_max} given the tenant's working situation"
end
if record.weekly_net_income < record.applicable_income_range.hard_min
record.errors.add :net_income, "Net income cannot be less than #{record.applicable_income_range.hard_min} given the tenant's working situation"
record.errors.add :earnings, "Net income cannot be less than #{record.applicable_income_range.hard_min} given the tenant's working situation"
end
end
end

54
app/validations/household_validations.rb

@ -2,14 +2,14 @@ module HouseholdValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well
def validate_reasonable_preference(record)
if record.homelessness == "No" && record.reasonable_preference == "Yes"
record.errors.add :reasonable_preference, "Can not be Yes if Not Homeless immediately prior to this letting has been selected"
elsif record.reasonable_preference == "Yes"
if !record.reasonable_preference_reason_homeless && !record.reasonable_preference_reason_unsatisfactory_housing && !record.reasonable_preference_reason_medical_grounds && !record.reasonable_preference_reason_avoid_hardship && !record.reasonable_preference_reason_do_not_know
if record.homeless == "No" && record.reasonpref == "Yes"
record.errors.add :reasonpref, "Can not be Yes if Not Homeless immediately prior to this letting has been selected"
elsif record.reasonpref == "Yes"
if !record.rp_homeless && !record.rp_insan_unsat && !record.rp_medwel && !record.rp_hardship && !record.rp_dontknow
record.errors.add :reasonable_preference_reason, "If reasonable preference is Yes, a reason must be given"
end
elsif record.reasonable_preference == "No"
if record.reasonable_preference_reason_homeless || record.reasonable_preference_reason_unsatisfactory_housing || record.reasonable_preference_reason_medical_grounds || record.reasonable_preference_reason_avoid_hardship || record.reasonable_preference_reason_do_not_know
elsif record.reasonpref == "No"
if record.rp_homeless || record.rp_insan_unsat || record.rp_medwel || record.rp_hardship || record.rp_dontknow
record.errors.add :reasonable_preference_reason, "If reasonable preference is No, no reasons should be given"
end
end
@ -20,34 +20,34 @@ module HouseholdValidations
end
def validate_reason_for_leaving_last_settled_home(record)
if record.reason_for_leaving_last_settled_home == "Do not know" && record.benefit_cap_spare_room_subsidy != "Do not know"
record.errors.add :benefit_cap_spare_room_subsidy, "must be do not know if tenant’s main reason for leaving is do not know"
if record.reason_for_leaving_last_settled_home == "Do not know" && record.underoccupation_benefitcap != "Do not know"
record.errors.add :underoccupation_benefitcap, "must be do not know if tenant’s main reason for leaving is do not know"
end
end
def validate_armed_forces_injured(record)
if (record.armed_forces == "Yes - a regular" || record.armed_forces == "Yes - a reserve") && record.armed_forces_injured.blank?
record.errors.add :armed_forces_injured, "You must answer the armed forces injury question if the tenant has served in the armed forces"
if (record.armed_forces == "Yes - a regular" || record.armed_forces == "Yes - a reserve") && record.reservist.blank?
record.errors.add :reservist, "You must answer the armed forces injury question if the tenant has served in the armed forces"
end
if (record.armed_forces == "No" || record.armed_forces == "Prefer not to say") && record.armed_forces_injured.present?
record.errors.add :armed_forces_injured, "You must not answer the armed forces injury question if the tenant has not served in the armed forces or prefer not to say was chosen"
if (record.armed_forces == "No" || record.armed_forces == "Prefer not to say") && record.reservist.present?
record.errors.add :reservist, "You must not answer the armed forces injury question if the tenant has not served in the armed forces or prefer not to say was chosen"
end
end
def validate_armed_forces_active_response(record)
if record.armed_forces == "Yes - a regular" && record.armed_forces_active.blank?
record.errors.add :armed_forces_active, "You must answer the armed forces active question if the tenant has served as a regular in the armed forces"
if record.armed_forces == "Yes - a regular" && record.leftreg.blank?
record.errors.add :leftreg, "You must answer the armed forces active question if the tenant has served as a regular in the armed forces"
end
if record.armed_forces != "Yes - a regular" && record.armed_forces_active.present?
record.errors.add :armed_forces_active, "You must not answer the armed forces active question if the tenant has not served as a regular in the armed forces"
if record.armed_forces != "Yes - a regular" && record.leftreg.present?
record.errors.add :leftreg, "You must not answer the armed forces active question if the tenant has not served as a regular in the armed forces"
end
end
def validate_household_pregnancy(record)
if (record.pregnancy == "Yes" || record.pregnancy == "Prefer not to say") && !women_of_child_bearing_age_in_household(record)
record.errors.add :pregnancy, "You must answer no as there are no female tenants aged 16-50 in the property"
if (record.preg_occ == "Yes" || record.preg_occ == "Prefer not to say") && !women_of_child_bearing_age_in_household(record)
record.errors.add :preg_occ, "You must answer no as there are no female tenants aged 16-50 in the property"
end
end
@ -75,17 +75,17 @@ module HouseholdValidations
end
def validate_shared_housing_rooms(record)
unless record.property_unit_type.nil?
if record.property_unit_type == "Bed-sit" && record.property_number_of_bedrooms != 1
record.errors.add :property_unit_type, "A bedsit can only have one bedroom"
unless record.unittype_gn.nil?
if record.unittype_gn == "Bed-sit" && record.beds != 1
record.errors.add :unittype_gn, "A bedsit can only have one bedroom"
end
if !record.household_number_of_other_members.nil? && record.household_number_of_other_members.positive? && (record.property_unit_type.include?("Shared") && !record.property_number_of_bedrooms.to_i.between?(1, 7))
record.errors.add :property_unit_type, "A shared house must have 1 to 7 bedrooms"
if !record.hhmemb.nil? && record.hhmemb.positive? && (record.unittype_gn.include?("Shared") && !record.beds.to_i.between?(1, 7))
record.errors.add :unittype_gn, "A shared house must have 1 to 7 bedrooms"
end
if record.property_unit_type.include?("Shared") && !record.property_number_of_bedrooms.to_i.between?(1, 3)
record.errors.add :property_unit_type, "A shared house with less than two tenants must have 1 to 3 bedrooms"
if record.unittype_gn.include?("Shared") && !record.beds.to_i.between?(1, 3)
record.errors.add :unittype_gn, "A shared house with less than two tenants must have 1 to 3 bedrooms"
end
end
end
@ -94,9 +94,9 @@ private
def women_of_child_bearing_age_in_household(record)
(1..8).any? do |n|
next if record["person_#{n}_gender"].nil? || record["person_#{n}_age"].nil?
next if record["sex#{n}"].nil? || record["age#{n}"].nil?
record["person_#{n}_gender"] == "Female" && record["person_#{n}_age"] >= 16 && record["person_#{n}_age"] <= 50
record["sex#{n}"] == "Female" && record["age#{n}"] >= 16 && record["age#{n}"] <= 50
end
end

4
app/validations/property_validations.rb

@ -2,8 +2,8 @@ module PropertyValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well
def validate_property_number_of_times_relet(record)
if record.property_number_of_times_relet && !/^[1-9]$|^0[1-9]$|^1[0-9]$|^20$/.match?(record.property_number_of_times_relet.to_s)
record.errors.add :property_number_of_times_relet, "Property number of times relet must be between 0 and 20"
if record.offered && !/^[1-9]$|^0[1-9]$|^1[0-9]$|^20$/.match?(record.offered.to_s)
record.errors.add :offered, "Must be between 0 and 20"
end
end
end

12
app/validations/tenancy_validations.rb

@ -2,20 +2,20 @@ module TenancyValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well
def validate_fixed_term_tenancy(record)
is_present = record.fixed_term_tenancy.present?
is_in_range = record.fixed_term_tenancy.to_i.between?(2, 99)
is_secure = record.tenancy_type == "Fixed term – Secure"
is_ast = record.tenancy_type == "Fixed term – Assured Shorthold Tenancy (AST)"
is_present = record.tenancylength.present?
is_in_range = record.tenancylength.to_i.between?(2, 99)
is_secure = record.tenancy == "Fixed term – Secure"
is_ast = record.tenancy == "Fixed term – Assured Shorthold Tenancy (AST)"
conditions = [
{ condition: !(is_secure || is_ast) && is_present, error: "You must only answer the fixed term tenancy length question if the tenancy type is fixed term" },
{ condition: is_ast && !is_in_range, error: "Fixed term – Assured Shorthold Tenancy (AST) should be between 2 and 99 years" },
{ condition: is_secure && (!is_in_range && is_present), error: "Fixed term – Secure should be between 2 and 99 years or not specified" },
]
conditions.each { |condition| condition[:condition] ? (record.errors.add :fixed_term_tenancy, condition[:error]) : nil }
conditions.each { |condition| condition[:condition] ? (record.errors.add :tenancylength, condition[:error]) : nil }
end
def validate_other_tenancy_type(record)
validate_other_field(record, "tenancy_type", "other_tenancy_type")
validate_other_field(record, "tenancy", "tenancyother")
end
end

296
config/forms/2021_2022.json

@ -21,11 +21,11 @@
}
}
},
"AGE1": {
"age1": {
"header": "",
"description": "",
"questions": {
"AGE1": {
"age1": {
"check_answer_label": "Tenant's age",
"header": "What is the tenant's age?",
"hint_text": "",
@ -36,11 +36,11 @@
}
}
},
"SEX1": {
"sex1": {
"header": "",
"description": "",
"questions": {
"SEX1": {
"sex1": {
"check_answer_label": "Tenant's gender",
"header": "Which of these best describes the tenant's gender identity?",
"hint_text": "",
@ -58,7 +58,7 @@
"header": "",
"description": "",
"questions": {
"ETHNIC": {
"ethnic": {
"check_answer_label": "Ethnicity",
"header": "What is the tenant's ethnic group?",
"hint_text": "",
@ -91,7 +91,7 @@
"header": "",
"description": "",
"questions": {
"NATIONAL": {
"national": {
"check_answer_label": "Nationality",
"header": "What is the tenant's nationality?",
"hint_text": "",
@ -121,7 +121,7 @@
"header": "",
"description": "",
"questions": {
"ECSTAT1": {
"ecstat1": {
"check_answer_label": "Work",
"header": "Which of these best describes the tenant's working situation?",
"hint_text": "",
@ -146,7 +146,7 @@
"header": "",
"description": "",
"questions": {
"HHMEMB": {
"hhmemb": {
"check_answer_label": "Number of Other Household Members",
"header": "How many other people are there in the household?",
"hint_text": "The maximum number of others is 7",
@ -155,37 +155,37 @@
"max": 7,
"step": 1,
"conditional_for": {
"person_2_relationship": ">0",
"person_2_age": ">0",
"person_2_gender": ">0",
"person_2_economic_status": ">0",
"person_3_relationship": ">1",
"person_3_age": ">1",
"person_3_gender": ">1",
"person_3_economic_status": ">1",
"person_4_relationship": ">2",
"person_4_age": ">2",
"person_4_gender": ">2",
"person_4_economic_status": ">2",
"person_5_relationship": ">3",
"person_5_age": ">3",
"person_5_gender": ">3",
"person_5_economic_status": ">3",
"person_6_relationship": ">4",
"person_6_age": ">4",
"person_6_gender": ">4",
"person_6_economic_status": ">4",
"person_7_relationship": ">5",
"person_7_age": ">5",
"person_7_gender": ">5",
"person_7_economic_status": ">5",
"person_8_relationship": ">6",
"person_8_age": ">6",
"person_8_gender": ">6",
"person_8_economic_status": ">6"
"relat2": ">0",
"age2": ">0",
"sex2": ">0",
"ecstat2": ">0",
"relat3": ">1",
"age3": ">1",
"sex3": ">1",
"ecstat3": ">1",
"relat4": ">2",
"age4": ">2",
"sex4": ">2",
"ecstat4": ">2",
"relat5": ">3",
"age5": ">3",
"sex5": ">3",
"ecstat5": ">3",
"relat6": ">4",
"age6": ">4",
"sex6": ">4",
"ecstat6": ">4",
"relat7": ">5",
"age7": ">5",
"sex7": ">5",
"ecstat7": ">5",
"relat8": ">6",
"age8": ">6",
"sex8": ">6",
"ecstat8": ">6"
}
},
"RELAT2": {
"relat2": {
"check_answer_label": "Person 2's relationship to lead tenant",
"header": "What's person 2's relationship to lead tenant",
"hint_text": "",
@ -197,7 +197,7 @@
"3": "Prefer not to say"
}
},
"AGE2": {
"age2": {
"check_answer_label": "Person 2's age",
"header": "What's person 2's age",
"hint_text": "",
@ -206,7 +206,7 @@
"max": 150,
"step": 1
},
"SEX2": {
"sex2": {
"check_answer_label": "Person 2's gender",
"header": "Which of these best describes person 2's gender identity?",
"hint_text": "",
@ -218,7 +218,7 @@
"3": "Prefer not to say"
}
},
"ECSTAT2": {
"ecstat2": {
"check_answer_label": "Person 2's Work",
"header": "Which of these best describes person 2's working situation?",
"hint_text": "",
@ -237,7 +237,7 @@
"10": "Prefer not to say"
}
},
"RELAT3": {
"relat3": {
"check_answer_label": "Person 3's relationship to lead tenant",
"header": "What's person 3's relationship to lead tenant",
"hint_text": "",
@ -249,7 +249,7 @@
"3": "Prefer not to say"
}
},
"AGE3": {
"age3": {
"check_answer_label": "Person 3's age",
"header": "What's person 3's age",
"hint_text": "",
@ -258,7 +258,7 @@
"max": 150,
"step": 1
},
"SEX3": {
"sex3": {
"check_answer_label": "Person 3's gender",
"header": "Which of these best describes person 3's gender identity?",
"hint_text": "",
@ -270,7 +270,7 @@
"3": "Prefer not to say"
}
},
"ECSTAT3": {
"ecstat3": {
"check_answer_label": "Person 3's Work",
"header": "Which of these best describes person 3's working situation?",
"hint_text": "",
@ -289,7 +289,7 @@
"10": "Prefer not to say"
}
},
"RELAT4": {
"relat4": {
"check_answer_label": "Person 4's relationship to lead tenant",
"header": "What's person 4's relationship to lead tenant",
"hint_text": "",
@ -301,7 +301,7 @@
"3": "Prefer not to say"
}
},
"AGE4": {
"age4": {
"check_answer_label": "Person 4's age",
"header": "What's person 4's age",
"hint_text": "",
@ -310,7 +310,7 @@
"max": 150,
"step": 1
},
"SEX4": {
"sex4": {
"check_answer_label": "Person 4's gender",
"header": "Which of these best describes person 4's gender identity?",
"hint_text": "",
@ -322,7 +322,7 @@
"3": "Prefer not to say"
}
},
"ECSTAT4": {
"ecstat4": {
"check_answer_label": "Person 4's Work",
"header": "Which of these best describes person 4's working situation?",
"hint_text": "",
@ -341,7 +341,7 @@
"10": "Prefer not to say"
}
},
"RELAT5": {
"relat5": {
"check_answer_label": "Person 5's relationship to lead tenant",
"header": "What's person 5's relationship to lead tenant",
"hint_text": "",
@ -353,7 +353,7 @@
"3": "Prefer not to say"
}
},
"AGE5": {
"age5": {
"check_answer_label": "Person 5's age",
"header": "What's person 5's age",
"hint_text": "",
@ -362,7 +362,7 @@
"max": 150,
"step": 1
},
"SEX5": {
"sex5": {
"check_answer_label": "Person 5's gender",
"header": "Which of these best describes person 5's gender identity?",
"hint_text": "",
@ -374,7 +374,7 @@
"3": "Prefer not to say"
}
},
"ECSTAT5": {
"ecstat5": {
"check_answer_label": "Person 5's Work",
"header": "Which of these best describes person 5's working situation?",
"hint_text": "",
@ -393,7 +393,7 @@
"10": "Prefer not to say"
}
},
"RELAT6": {
"relat6": {
"check_answer_label": "Person 6's relationship to lead tenant",
"header": "What's person 6's relationship to lead tenant",
"hint_text": "",
@ -405,7 +405,7 @@
"3": "Prefer not to say"
}
},
"AGE6": {
"age6": {
"check_answer_label": "Person 6's age",
"header": "What's person 6's age",
"hint_text": "",
@ -414,7 +414,7 @@
"max": 150,
"step": 1
},
"SEX6": {
"sex6": {
"check_answer_label": "Person 6's gender",
"header": "Which of these best describes person 6's gender identity?",
"hint_text": "",
@ -426,7 +426,7 @@
"3": "Prefer not to say"
}
},
"ECSTAT6": {
"ecstat6": {
"check_answer_label": "Person 6's Work",
"header": "Which of these best describes person 6's working situation?",
"hint_text": "",
@ -445,7 +445,7 @@
"10": "Prefer not to say"
}
},
"RELAT7": {
"relat7": {
"check_answer_label": "Person 7's relationship to lead tenant",
"header": "What's person 7's relationship to lead tenant",
"hint_text": "",
@ -457,7 +457,7 @@
"3": "Prefer not to say"
}
},
"AGE7": {
"age7": {
"check_answer_label": "Person 7's age",
"header": "What's person 7's age",
"hint_text": "",
@ -466,7 +466,7 @@
"max": 150,
"step": 1
},
"SEX7": {
"sex7": {
"check_answer_label": "Person 7's gender",
"header": "Which of these best describes person 7's gender identity?",
"hint_text": "",
@ -478,7 +478,7 @@
"3": "Prefer not to say"
}
},
"ECSTAT7": {
"ecstat7": {
"check_answer_label": "Person 7's Work",
"header": "Which of these best describes person 7's working situation?",
"hint_text": "",
@ -497,7 +497,7 @@
"10": "Prefer not to say"
}
},
"RELAT8": {
"relat8": {
"check_answer_label": "Person 8's relationship to lead tenant",
"header": "What's person 8's relationship to lead tenant",
"hint_text": "",
@ -509,7 +509,7 @@
"3": "Prefer not to say"
}
},
"AGE8": {
"age8": {
"check_answer_label": "Person 8's age",
"header": "What's person 8's age",
"hint_text": "",
@ -518,7 +518,7 @@
"max": 150,
"step": 1
},
"SEX8": {
"sex8": {
"check_answer_label": "Person 8's gender",
"header": "Which of these best describes person 8's gender identity?",
"hint_text": "",
@ -530,7 +530,7 @@
"3": "Prefer not to say"
}
},
"ECSTAT8": {
"ecstat8": {
"check_answer_label": "Person 8's Work",
"header": "Which of these best describes person 8's working situation?",
"hint_text": "",
@ -560,7 +560,7 @@
"header": "",
"description": "",
"questions": {
"PREVTEN": {
"prevten": {
"header": "What was the tenant’s housing situation immediately before this letting?",
"hint_text": "",
"type": "radio",
@ -596,7 +596,7 @@
"header": "",
"description": "",
"questions": {
"HOMELESS": {
"homeless": {
"header": "Did the tenant experience homelessness immediately before this letting?",
"hint_text": "",
"type": "radio",
@ -661,7 +661,7 @@
"hint_text": "",
"type": "text"
},
"UNDEROCCUPATION_BENEFITCAP": {
"underoccupation_benefitcap": {
"header": "Was the reason for leaving because of the benefit cap or removal of the spare room subsidy?",
"hint_text": "",
"type": "radio",
@ -697,17 +697,11 @@
"3": "Prefer not to say"
},
"conditional_for": {
"armed_forces_active": [
"Yes - a regular",
"Yes - a reserve"
],
"armed_forces_injured": [
"Yes - a regular",
"Yes - a reserve"
]
"leftreg": ["Yes - a regular", "Yes - a reserve"],
"reservist": ["Yes - a regular", "Yes - a reserve"]
}
},
"LEFTREG": {
"leftreg": {
"header": "Are they still serving?",
"hint_text": "",
"type": "radio",
@ -719,7 +713,7 @@
"3": "Prefer not to say"
}
},
"RESERVIST": {
"reservist": {
"header": "Were they seriously injured or ill as a result of their service?",
"hint_text": "",
"type": "radio",
@ -766,7 +760,7 @@
"header": "",
"description": "",
"questions": {
"PREG_OCC": {
"preg_occ": {
"header": "Is anyone in the household pregnant?",
"hint_text": "",
"type": "radio",
@ -789,13 +783,13 @@
"type": "checkbox",
"check_answer_label": "Disability requirements",
"answer_options": {
"HousingNeeds_A": "Fully wheelchair accessible housing",
"HousingNeeds_B": "Wheelchair access to essential rooms",
"HousingNeeds_C": "Level access housing",
"HousingNeeds_F": "Other disability requirements",
"HousingNeeds_G": "No disability requirements",
"housingneeds_a": "Fully wheelchair accessible housing",
"housingneeds_b": "Wheelchair access to essential rooms",
"housingneeds_c": "Level access housing",
"housingneeds_f": "Other disability requirements",
"housingneeds_g": "No disability requirements",
"divider_a": true,
"HousingNeeds_H": "Do not know",
"housingneeds_h": "Do not know",
"divider_b": true,
"accessibility_requirements_prefer_not_to_say": "Prefer not to say"
}
@ -812,16 +806,16 @@
"type": "checkbox",
"check_answer_label": "Conditions or illnesses",
"answer_options": {
"ILLNESS_TYPE_1": "Vision - such as blindness or partial sight",
"ILLNESS_TYPE_2": "Hearing - such as deafness or partial hearing",
"ILLNESS_TYPE_3": "Mobility - such as walking short distances or climbing stairs",
"ILLNESS_TYPE_4": "Dexterity - such as lifting and carrying objects or using a keyboard",
"ILLNESS_TYPE_8": "Stamina or breathing or fatigue",
"ILLNESS_TYPE_5": "Learning or understanding or concentrating",
"ILLNESS_TYPE_6": "Memory",
"ILLNESS_TYPE_7": "Mental health - such as depression, anxiety, schizophrenia or bipolar",
"ILLNESS_TYPE_9": "Socially or behaviourally - such as those associated with autism spectral disorder (ASD) including Aspergers’ or attention deficit hyperactivity disorder (ADHD))",
"ILLNESS_TYPE_10": "Other",
"illness_type_1": "Vision - such as blindness or partial sight",
"illness_type_2": "Hearing - such as deafness or partial hearing",
"illness_type_3": "Mobility - such as walking short distances or climbing stairs",
"illness_type_4": "Dexterity - such as lifting and carrying objects or using a keyboard",
"illness_type_8": "Stamina or breathing or fatigue",
"illness_type_5": "Learning or understanding or concentrating",
"illness_type_6": "Memory",
"illness_type_7": "Mental health - such as depression, anxiety, schizophrenia or bipolar",
"illness_type_9": "Socially or behaviourally - such as those associated with autism spectral disorder (ASD) including Aspergers’ or attention deficit hyperactivity disorder (ADHD))",
"illness_type_10": "Other",
"divider": true,
"condition_effects_prefer_not_to_say": "Prefer not to say"
}
@ -854,7 +848,7 @@
"header": "",
"description": "",
"questions": {
"STARTDATE": {
"startdate": {
"check_answer_label": "When is the tenancy start date?",
"header": "What is the tenancy start date?",
"hint_text": "For example, 27 3 2007",
@ -866,7 +860,7 @@
"header": "",
"description": "",
"questions": {
"STARTERTENANCY": {
"startertenancy": {
"check_answer_label": "Is this a starter or introductory tenancy?",
"header": "Is this a starter tenancy?",
"hint_text": "",
@ -882,7 +876,7 @@
"header": "",
"description": "",
"questions": {
"TENANCYLENGTH": {
"tenancylength": {
"check_answer_label": "If the main tenancy is a fixed term tenancy, please provide the length of the fixed term (to the nearest year) excluding any starter/introductory period",
"header": "If fixed-term, what is the length of the fixed-term tenancy after any starter period?",
"hint_text": "To the nearest year",
@ -897,7 +891,7 @@
"header": "",
"description": "",
"questions": {
"TENANCY": {
"tenancy": {
"check_answer_label": "Type of main tenancy (after any starter/introductory period)",
"header": "What is the type of tenancy after the starter period has ended?",
"hint_text": "",
@ -914,7 +908,7 @@
"other_tenancy_type": ["Other"]
}
},
"TENANCYOTHER": {
"tenancyother": {
"header": "Please state the tenancy type",
"hint_text": "",
"type": "text"
@ -925,7 +919,7 @@
"header": "",
"description": "",
"questions": {
"LETTYPE": {
"lettype": {
"check_answer_label": "Type of letting",
"header": "Which type of letting is this?",
"hint_text": "",
@ -945,7 +939,7 @@
"header": "",
"description": "",
"questions": {
"LANDLORD": {
"landlord": {
"check_answer_label": "Provider",
"header": "Who is the letting provider?",
"hint_text": "",
@ -1321,7 +1315,7 @@
"header": "",
"description": "",
"questions": {
"RSNVAC": {
"rsnvac": {
"check_answer_label": "What is the reason for the property vacancy?",
"header": "What is the reason for the property vacancy?",
"hint_text": "",
@ -1361,7 +1355,7 @@
"header": "",
"description": "",
"questions": {
"UNITTYPE_GN": {
"unittype_gn": {
"check_answer_label": "Which type of unit is the property?",
"header": "Which type of unit is the property?",
"hint_text": "",
@ -1383,7 +1377,7 @@
"header": "",
"description": "",
"questions": {
"BEDS": {
"beds": {
"check_answer_label": "How many bedrooms are there in the property?",
"header": "How many bedrooms are there in the property?",
"hint_text": "If shared accommodation, enter number of bedrooms occupied by this household; a bed-sit has 1 bedroom",
@ -1423,7 +1417,7 @@
"header": "",
"description": "",
"questions": {
"OFFERED": {
"offered": {
"check_answer_label": "How many times has this unit been previously offered since becoming available for relet since the last tenancy ended or as a first let?",
"header": "How many times has this unit been previously offered since becoming available for relet since the last tenancy ended or as a first let? ",
"hint_text": "For an Affordable Rent or Intermediate Rent Letting, only include number of offers as that type. For a property let at the first attempt enter '0' ",
@ -1438,7 +1432,7 @@
"header": "",
"description": "",
"questions": {
"WCHAIR": {
"wchair": {
"check_answer_label": "Is property built or adapted to wheelchair user standards?",
"header": "Is property built or adapted to wheelchair user standards?",
"hint_text": "",
@ -1475,11 +1469,11 @@
"2": "Tenant prefers not to say"
},
"conditional_for": {
"net_income": ["Yes"],
"net_income_frequency": ["Yes"]
"earnings": ["Yes"],
"incfreq": ["Yes"]
}
},
"EARNINGS": {
"earnings": {
"check_answer_label": "Income",
"header": "What is the tenant’s /and partner’s combined income after tax?",
"hint_text": "",
@ -1487,7 +1481,7 @@
"min": 0,
"step": "1"
},
"INCFREQ": {
"incfreq": {
"check_answer_label": "Income Frequency",
"header": "How often do they receive this income?",
"hint_text": "",
@ -1513,7 +1507,7 @@
"header": "",
"description": "",
"questions": {
"BENEFITS": {
"benefits": {
"check_answer_label": "Benefits as a proportion of income",
"header": "How much of the tenant’s income is from Universal Credit, state pensions or benefits?",
"hint_text": "",
@ -1557,7 +1551,7 @@
"header": "",
"description": "",
"questions": {
"PERIOD": {
"period": {
"check_answer_label": "Rent Period",
"header": "Which period are rent and other charges due?",
"hint_text": "",
@ -1575,7 +1569,7 @@
"9": "Weekly for 53 weeks"
}
},
"BRENT": {
"brent": {
"check_answer_label": "Basic Rent",
"header": "What is the basic rent?",
"hint_text": "Eligible for housing benefit or Universal Credit",
@ -1583,14 +1577,14 @@
"min": 0,
"step": 1,
"fields-to-add": [
"basic_rent",
"service_charge",
"personal_service_charge",
"support_charge"
"brent",
"scharge",
"pscharge",
"supcharge"
],
"result-field": "total_charge"
"result-field": "tcharge"
},
"SCHARGE": {
"scharge": {
"check_answer_label": "Service Charge",
"header": "What is the service charge?",
"hint_text": "Eligible for housing benefit or Universal Credit",
@ -1598,14 +1592,14 @@
"min": 0,
"step": 1,
"fields-to-add": [
"basic_rent",
"service_charge",
"personal_service_charge",
"support_charge"
"brent",
"scharge",
"pscharge",
"supcharge"
],
"result-field": "total_charge"
"result-field": "tcharge"
},
"PSCHARGE": {
"pscharge": {
"check_answer_label": "Personal Service Charge",
"header": "What is the personal service charge?",
"hint_text": "Not eligible for housing benefit or Universal Credit. For example, hot water excluding water rates.",
@ -1613,14 +1607,14 @@
"min": 0,
"step": 1,
"fields-to-add": [
"basic_rent",
"service_charge",
"personal_service_charge",
"support_charge"
"brent",
"scharge",
"pscharge",
"supcharge"
],
"result-field": "total_charge"
"result-field": "tcharge"
},
"SUPCHARGE": {
"supcharge": {
"check_answer_label": "Support Charge",
"header": "What is the support charge?",
"hint_text": "This is to fund housing-related support services included in the tenancy agreement",
@ -1628,14 +1622,14 @@
"min": 0,
"step": 1,
"fields-to-add": [
"basic_rent",
"service_charge",
"personal_service_charge",
"support_charge"
"brent",
"scharge",
"pscharge",
"supcharge"
],
"result-field": "total_charge"
"result-field": "tcharge"
},
"TCHARGE": {
"tcharge": {
"check_answer_label": "Total Charge",
"header": "Total charge?",
"hint_text": "This is the total of rent and all charges",
@ -1681,7 +1675,7 @@
"header": "",
"description": "",
"questions": {
"LAYEAR": {
"layear": {
"check_answer_label": "How long has the household continuously lived in the local authority area where the new letting is located?",
"header": "How long has the household continuously lived in the local authority area where the new letting is located?",
"hint_text": "",
@ -1703,7 +1697,7 @@
"header": "",
"description": "",
"questions": {
"LAWAITLIST": {
"lawaitlist": {
"check_answer_label": "How long has the household been on the local authority waiting list where the new letting is located?",
"header": "How long has the household been on the local authority waiting list where the new letting is located?",
"hint_text": "",
@ -2064,7 +2058,7 @@
"header": "",
"description": "",
"questions": {
"REASONPREF": {
"reasonpref": {
"check_answer_label": "Was the household given Reasonable Preference (i.e. priority) for housing by the Local Authority?",
"header": "Was the household given reasonable preference by the local authority?",
"hint_text": "",
@ -2083,12 +2077,12 @@
"hint_text": "Select all that apply",
"type": "checkbox",
"answer_options": {
"RP_HOMELESS": "Homeless or about to lose their home (within 56 days)",
"RP_INSAN_UNSAT": "Living in insanitary or overcrowded or unsatisfactory housing",
"RP_MEDWEL": "A need to move on medical and welfare grounds (including a disability)",
"RP_HARDSHIP": "A need to move to avoid hardship to themselves or others",
"rp_homeless": "Homeless or about to lose their home (within 56 days)",
"rp_insan_unsat": "Living in insanitary or overcrowded or unsatisfactory housing",
"rp_medwel": "A need to move on medical and welfare grounds (including a disability)",
"rp_hardship": "A need to move to avoid hardship to themselves or others",
"divider": true,
"RP_DONTKNOW": "Do not know"
"rp_dontknow": "Do not know"
}
}
}
@ -2097,9 +2091,9 @@
"header": "",
"description": "",
"questions": {
"CBL": {
"cbl": {
"check_answer_label": "Choice-based letting?",
"header": "Was the letting made under choice-based lettings (CBL)? ",
"header": "Was the letting made under choice-based lettings (cbl)? ",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -2107,9 +2101,9 @@
"1": "No"
}
},
"CHR": {
"chr": {
"check_answer_label": "Common housing register letting?",
"header": "Was the letting made under common housing register (CHR)? ",
"header": "Was the letting made under common housing register (chr)? ",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -2117,9 +2111,9 @@
"1": "No"
}
},
"CAP": {
"cap": {
"check_answer_label": "Common allocation policy letting?",
"header": "Was the letting made under common allocation policy (CAP)? ",
"header": "Was the letting made under common allocation policy (cap)? ",
"hint_text": "",
"type": "radio",
"answer_options": {

178
db/migrate/20211101192151_rename_fields.rb

@ -1,107 +1,107 @@
class RenameFields < ActiveRecord::Migration[6.1]
def change
rename_column :case_logs, :person_1_age, :AGE1
rename_column :case_logs, :person_1_gender, :SEX1
rename_column :case_logs, :tenant_ethnic_group, :ETHNIC
rename_column :case_logs, :tenant_nationality, :NATIONAL
rename_column :case_logs, :tenant_economic_status, :ECSTAT1
rename_column :case_logs, :household_number_of_other_members, :HHMEMB
rename_column :case_logs, :person_1_age, :age1
rename_column :case_logs, :person_1_gender, :sex1
rename_column :case_logs, :tenant_ethnic_group, :ethnic
rename_column :case_logs, :tenant_nationality, :national
rename_column :case_logs, :person_1_economic_status, :ecstat1
rename_column :case_logs, :household_number_of_other_members, :hhmemb
rename_column :case_logs, :person_2_relationship, :RELAT2
rename_column :case_logs, :person_2_age, :AGE2
rename_column :case_logs, :person_2_gender, :SEX2
rename_column :case_logs, :person_2_economic_status, :ECSTAT2
rename_column :case_logs, :person_2_relationship, :relat2
rename_column :case_logs, :person_2_age, :age2
rename_column :case_logs, :person_2_gender, :sex2
rename_column :case_logs, :person_2_economic_status, :ecstat2
rename_column :case_logs, :person_3_relationship, :RELAT3
rename_column :case_logs, :person_3_age, :AGE3
rename_column :case_logs, :person_3_gender, :SEX3
rename_column :case_logs, :person_3_economic_status, :ECSTAT3
rename_column :case_logs, :person_3_relationship, :relat3
rename_column :case_logs, :person_3_age, :age3
rename_column :case_logs, :person_3_gender, :sex3
rename_column :case_logs, :person_3_economic_status, :ecstat3
rename_column :case_logs, :person_4_relationship, :RELAT4
rename_column :case_logs, :person_4_age, :AGE4
rename_column :case_logs, :person_4_gender, :SEX4
rename_column :case_logs, :person_4_economic_status, :ECSTAT4
rename_column :case_logs, :person_4_relationship, :relat4
rename_column :case_logs, :person_4_age, :age4
rename_column :case_logs, :person_4_gender, :sex4
rename_column :case_logs, :person_4_economic_status, :ecstat4
rename_column :case_logs, :person_5_relationship, :RELAT5
rename_column :case_logs, :person_5_age, :AGE5
rename_column :case_logs, :person_5_gender, :SEX5
rename_column :case_logs, :person_5_economic_status, :ECSTAT5
rename_column :case_logs, :person_5_relationship, :relat5
rename_column :case_logs, :person_5_age, :age5
rename_column :case_logs, :person_5_gender, :sex5
rename_column :case_logs, :person_5_economic_status, :ecstat5
rename_column :case_logs, :person_6_relationship, :RELAT6
rename_column :case_logs, :person_6_age, :AGE6
rename_column :case_logs, :person_6_gender, :SEX6
rename_column :case_logs, :person_6_economic_status, :ECSTAT6
rename_column :case_logs, :person_6_relationship, :relat6
rename_column :case_logs, :person_6_age, :age6
rename_column :case_logs, :person_6_gender, :sex6
rename_column :case_logs, :person_6_economic_status, :ecstat6
rename_column :case_logs, :person_7_relationship, :RELAT7
rename_column :case_logs, :person_7_age, :AGE7
rename_column :case_logs, :person_7_gender, :SEX7
rename_column :case_logs, :person_7_economic_status, :ECSTAT7
rename_column :case_logs, :person_7_relationship, :relat7
rename_column :case_logs, :person_7_age, :age7
rename_column :case_logs, :person_7_gender, :sex7
rename_column :case_logs, :person_7_economic_status, :ecstat7
rename_column :case_logs, :person_8_relationship, :RELAT8
rename_column :case_logs, :person_8_age, :AGE8
rename_column :case_logs, :person_8_gender, :SEX8
rename_column :case_logs, :person_8_economic_status, :ECSTAT8
rename_column :case_logs, :person_8_relationship, :relat8
rename_column :case_logs, :person_8_age, :age8
rename_column :case_logs, :person_8_gender, :sex8
rename_column :case_logs, :person_8_economic_status, :ecstat8
rename_column :case_logs, :previous_housing_situation, :PREVTEN
rename_column :case_logs, :homelessness, :HOMELESS
rename_column :case_logs, :benefit_cap_spare_room_subsidy, :UNDEROCCUPATION_BENEFITCAP
rename_column :case_logs, :armed_forces_injured, :RESERVIST
rename_column :case_logs, :armed_forces_active, :LEFTREG
rename_column :case_logs, :medical_conditions, :ILLNESS
rename_column :case_logs, :pregnancy, :PREG_OCC
rename_column :case_logs, :previous_housing_situation, :prevten
rename_column :case_logs, :homelessness, :homeless
rename_column :case_logs, :benefit_cap_spare_room_subsidy, :underoccupation_benefitcap
rename_column :case_logs, :armed_forces_injured, :reservist
rename_column :case_logs, :armed_forces_active, :leftreg
rename_column :case_logs, :medical_conditions, :illness
rename_column :case_logs, :pregnancy, :preg_occ
rename_column :case_logs, :accessibility_requirements_fully_wheelchair_accessible_housing, :HousingNeeds_A
rename_column :case_logs, :accessibility_requirements_wheelchair_access_to_essential_rooms, :HousingNeeds_B
rename_column :case_logs, :accessibility_requirements_level_access_housing, :HousingNeeds_C
rename_column :case_logs, :accessibility_requirements_other_disability_requirements, :HousingNeeds_F
rename_column :case_logs, :accessibility_requirements_no_disability_requirements, :HousingNeeds_G
rename_column :case_logs, :accessibility_requirements_do_not_know, :HousingNeeds_H
rename_column :case_logs, :accessibility_requirements_fully_wheelchair_accessible_housing, :housingneeds_a
rename_column :case_logs, :accessibility_requirements_wheelchair_access_to_essential_rooms, :housingneeds_b
rename_column :case_logs, :accessibility_requirements_level_access_housing, :housingneeds_c
rename_column :case_logs, :accessibility_requirements_other_disability_requirements, :housingneeds_f
rename_column :case_logs, :accessibility_requirements_no_disability_requirements, :housingneeds_g
rename_column :case_logs, :accessibility_requirements_do_not_know, :housingneeds_h
rename_column :case_logs, :condition_effects_vision, :ILLNESS_TYPE_1
rename_column :case_logs, :condition_effects_hearing, :ILLNESS_TYPE_2
rename_column :case_logs, :condition_effects_mobility, :ILLNESS_TYPE_3
rename_column :case_logs, :condition_effects_dexterity, :ILLNESS_TYPE_4
rename_column :case_logs, :condition_effects_stamina, :ILLNESS_TYPE_8
rename_column :case_logs, :condition_effects_learning, :ILLNESS_TYPE_5
rename_column :case_logs, :condition_effects_memory, :ILLNESS_TYPE_6
rename_column :case_logs, :condition_effects_mental_health, :ILLNESS_TYPE_7
rename_column :case_logs, :condition_effects_social_or_behavioral, :ILLNESS_TYPE_9
rename_column :case_logs, :condition_effects_other, :ILLNESS_TYPE_10
rename_column :case_logs, :condition_effects_vision, :illness_type_1
rename_column :case_logs, :condition_effects_hearing, :illness_type_2
rename_column :case_logs, :condition_effects_mobility, :illness_type_3
rename_column :case_logs, :condition_effects_dexterity, :illness_type_4
rename_column :case_logs, :condition_effects_stamina, :illness_type_8
rename_column :case_logs, :condition_effects_learning, :illness_type_5
rename_column :case_logs, :condition_effects_memory, :illness_type_6
rename_column :case_logs, :condition_effects_mental_health, :illness_type_7
rename_column :case_logs, :condition_effects_social_or_behavioral, :illness_type_9
rename_column :case_logs, :condition_effects_other, :illness_type_10
rename_column :case_logs, :tenancy_start_date, :STARTDATE
rename_column :case_logs, :starter_tenancy, :STARTERTENANCY
rename_column :case_logs, :fixed_term_tenancy, :TENANCYLENGTH
rename_column :case_logs, :tenancy_type, :TENANCY
rename_column :case_logs, :other_tenancy_type, :TENANCYOTHER
rename_column :case_logs, :letting_type, :LETTYPE
rename_column :case_logs, :letting_provider, :LANDLORD
rename_column :case_logs, :property_vacancy_reason, :RSNVAC
rename_column :case_logs, :property_unit_type, :UNITTYPE_GN
rename_column :case_logs, :property_number_of_bedrooms, :BEDS
rename_column :case_logs, :property_number_of_times_relet, :OFFERED
rename_column :case_logs, :property_wheelchair_accessible, :WCHAIR
rename_column :case_logs, :net_income, :EARNINGS
rename_column :case_logs, :net_income_frequency, :INCFREQ
rename_column :case_logs, :net_income_uc_proportion, :BENEFITS
rename_column :case_logs, :rent_frequency, :PERIOD
rename_column :case_logs, :basic_rent, :BRENT
rename_column :case_logs, :service_charge, :SCHARGE
rename_column :case_logs, :personal_service_charge, :PSCHARGE
rename_column :case_logs, :support_charge, :SUPCHARGE
rename_column :case_logs, :total_charge, :TCHARGE
rename_column :case_logs, :time_lived_in_la, :LAYEAR
rename_column :case_logs, :time_on_la_waiting_list, :LAWAITLIST
rename_column :case_logs, :reasonable_preference, :REASONPREF
rename_column :case_logs, :tenancy_start_date, :startdate
rename_column :case_logs, :starter_tenancy, :startertenancy
rename_column :case_logs, :fixed_term_tenancy, :tenancylength
rename_column :case_logs, :tenancy_type, :tenancy
rename_column :case_logs, :other_tenancy_type, :tenancyother
rename_column :case_logs, :letting_type, :lettype
rename_column :case_logs, :letting_provider, :landlord
rename_column :case_logs, :property_vacancy_reason, :rsnvac
rename_column :case_logs, :property_unit_type, :unittype_gn
rename_column :case_logs, :property_number_of_bedrooms, :beds
rename_column :case_logs, :property_number_of_times_relet, :offered
rename_column :case_logs, :property_wheelchair_accessible, :wchair
rename_column :case_logs, :net_income, :earnings
rename_column :case_logs, :net_income_frequency, :incfreq
rename_column :case_logs, :net_income_uc_proportion, :benefits
rename_column :case_logs, :rent_frequency, :period
rename_column :case_logs, :basic_rent, :brent
rename_column :case_logs, :service_charge, :scharge
rename_column :case_logs, :personal_service_charge, :pscharge
rename_column :case_logs, :support_charge, :supcharge
rename_column :case_logs, :total_charge, :tcharge
rename_column :case_logs, :time_lived_in_la, :layear
rename_column :case_logs, :time_on_la_waiting_list, :lawaitlist
rename_column :case_logs, :reasonable_preference, :reasonpref
rename_column :case_logs, :reasonable_preference_reason_homeless, :RP_HOMELESS
rename_column :case_logs, :reasonable_preference_reason_unsatisfactory_housing, :RP_INSAN_UNSAT
rename_column :case_logs, :reasonable_preference_reason_medical_grounds, :RP_MEDWEL
rename_column :case_logs, :reasonable_preference_reason_avoid_hardship, :RP_HARDSHIP
rename_column :case_logs, :reasonable_preference_reason_do_not_know, :RP_DONTKNOW
rename_column :case_logs, :reasonable_preference_reason_homeless, :rp_homeless
rename_column :case_logs, :reasonable_preference_reason_unsatisfactory_housing, :rp_insan_unsat
rename_column :case_logs, :reasonable_preference_reason_medical_grounds, :rp_medwel
rename_column :case_logs, :reasonable_preference_reason_avoid_hardship, :rp_hardship
rename_column :case_logs, :reasonable_preference_reason_do_not_know, :rp_dontknow
rename_column :case_logs, :cbl_letting, :CBL
rename_column :case_logs, :chr_letting, :CHR
rename_column :case_logs, :cap_letting, :CAP
rename_column :case_logs, :cbl_letting, :cbl
rename_column :case_logs, :chr_letting, :chr
rename_column :case_logs, :cap_letting, :cap
end
end

180
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_10_28_095000) do
ActiveRecord::Schema.define(version: 2021_11_01_192151) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -20,120 +20,120 @@ ActiveRecord::Schema.define(version: 2021_10_28_095000) do
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "tenant_code"
t.integer "person_1_age"
t.string "person_1_gender"
t.string "tenant_ethnic_group"
t.string "tenant_nationality"
t.string "previous_housing_situation"
t.integer "age1"
t.string "sex1"
t.string "ethnic"
t.string "national"
t.string "prevten"
t.string "armed_forces"
t.string "person_1_economic_status"
t.integer "household_number_of_other_members"
t.string "person_2_relationship"
t.integer "person_2_age"
t.string "person_2_gender"
t.string "person_2_economic_status"
t.string "person_3_relationship"
t.integer "person_3_age"
t.string "person_3_gender"
t.string "person_3_economic_status"
t.string "person_4_relationship"
t.integer "person_4_age"
t.string "person_4_gender"
t.string "person_4_economic_status"
t.string "person_5_relationship"
t.integer "person_5_age"
t.string "person_5_gender"
t.string "person_5_economic_status"
t.string "person_6_relationship"
t.integer "person_6_age"
t.string "person_6_gender"
t.string "person_6_economic_status"
t.string "person_7_relationship"
t.integer "person_7_age"
t.string "person_7_gender"
t.string "person_7_economic_status"
t.string "person_8_relationship"
t.integer "person_8_age"
t.string "person_8_gender"
t.string "person_8_economic_status"
t.string "homelessness"
t.string "ecstat1"
t.integer "hhmemb"
t.string "relat2"
t.integer "age2"
t.string "sex2"
t.string "ecstat2"
t.string "relat3"
t.integer "age3"
t.string "sex3"
t.string "ecstat3"
t.string "relat4"
t.integer "age4"
t.string "sex4"
t.string "ecstat4"
t.string "relat5"
t.integer "age5"
t.string "sex5"
t.string "ecstat5"
t.string "relat6"
t.integer "age6"
t.string "sex6"
t.string "ecstat6"
t.string "relat7"
t.integer "age7"
t.string "sex7"
t.string "ecstat7"
t.string "relat8"
t.integer "age8"
t.string "sex8"
t.string "ecstat8"
t.string "homeless"
t.string "reason_for_leaving_last_settled_home"
t.string "benefit_cap_spare_room_subsidy"
t.string "armed_forces_active"
t.string "armed_forces_injured"
t.string "underoccupation_benefitcap"
t.string "leftreg"
t.string "reservist"
t.string "armed_forces_partner"
t.string "medical_conditions"
t.string "pregnancy"
t.string "illness"
t.string "preg_occ"
t.string "accessibility_requirements"
t.string "condition_effects"
t.string "tenancy_code"
t.string "tenancy_start_date"
t.string "starter_tenancy"
t.string "fixed_term_tenancy"
t.string "tenancy_type"
t.string "letting_type"
t.string "letting_provider"
t.string "startdate"
t.string "startertenancy"
t.string "tenancylength"
t.string "tenancy"
t.string "lettype"
t.string "landlord"
t.string "property_location"
t.string "previous_postcode"
t.string "property_relet"
t.string "property_vacancy_reason"
t.string "rsnvac"
t.string "property_reference"
t.string "property_unit_type"
t.string "unittype_gn"
t.string "property_building_type"
t.string "property_number_of_bedrooms"
t.string "beds"
t.string "property_void_date"
t.string "property_major_repairs"
t.string "property_major_repairs_date"
t.integer "property_number_of_times_relet"
t.string "property_wheelchair_accessible"
t.integer "net_income"
t.string "net_income_frequency"
t.string "net_income_uc_proportion"
t.integer "offered"
t.string "wchair"
t.integer "earnings"
t.string "incfreq"
t.string "benefits"
t.string "housing_benefit"
t.string "rent_frequency"
t.string "basic_rent"
t.string "service_charge"
t.string "personal_service_charge"
t.string "support_charge"
t.string "total_charge"
t.string "period"
t.string "brent"
t.string "scharge"
t.string "pscharge"
t.string "supcharge"
t.string "tcharge"
t.string "outstanding_amount"
t.string "time_lived_in_la"
t.string "time_on_la_waiting_list"
t.string "layear"
t.string "lawaitlist"
t.string "previous_la"
t.string "property_postcode"
t.string "reasonable_preference"
t.string "reasonpref"
t.string "reasonable_preference_reason"
t.string "cbl_letting"
t.string "chr_letting"
t.string "cap_letting"
t.string "cbl"
t.string "chr"
t.string "cap"
t.string "outstanding_rent_or_charges"
t.string "other_reason_for_leaving_last_settled_home"
t.boolean "accessibility_requirements_fully_wheelchair_accessible_housing"
t.boolean "accessibility_requirements_wheelchair_access_to_essential_rooms"
t.boolean "accessibility_requirements_level_access_housing"
t.boolean "accessibility_requirements_other_disability_requirements"
t.boolean "accessibility_requirements_no_disability_requirements"
t.boolean "accessibility_requirements_do_not_know"
t.boolean "housingneeds_a"
t.boolean "housingneeds_b"
t.boolean "housingneeds_c"
t.boolean "housingneeds_f"
t.boolean "housingneeds_g"
t.boolean "housingneeds_h"
t.boolean "accessibility_requirements_prefer_not_to_say"
t.boolean "condition_effects_vision"
t.boolean "condition_effects_hearing"
t.boolean "condition_effects_mobility"
t.boolean "condition_effects_dexterity"
t.boolean "condition_effects_stamina"
t.boolean "condition_effects_learning"
t.boolean "condition_effects_memory"
t.boolean "condition_effects_mental_health"
t.boolean "condition_effects_social_or_behavioral"
t.boolean "condition_effects_other"
t.boolean "illness_type_1"
t.boolean "illness_type_2"
t.boolean "illness_type_3"
t.boolean "illness_type_4"
t.boolean "illness_type_8"
t.boolean "illness_type_5"
t.boolean "illness_type_6"
t.boolean "illness_type_7"
t.boolean "illness_type_9"
t.boolean "illness_type_10"
t.boolean "condition_effects_prefer_not_to_say"
t.boolean "reasonable_preference_reason_homeless"
t.boolean "reasonable_preference_reason_unsatisfactory_housing"
t.boolean "reasonable_preference_reason_medical_grounds"
t.boolean "reasonable_preference_reason_avoid_hardship"
t.boolean "reasonable_preference_reason_do_not_know"
t.boolean "rp_homeless"
t.boolean "rp_insan_unsat"
t.boolean "rp_medwel"
t.boolean "rp_hardship"
t.boolean "rp_dontknow"
t.datetime "discarded_at"
t.string "other_tenancy_type"
t.boolean "override_net_income_validation"
t.string "tenancyother"
t.string "net_income_known"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
end

625
docs/api/DLUHC-CORE-Data.v1.json

File diff suppressed because it is too large Load Diff

58
spec/controllers/case_logs_controller_spec.rb

@ -49,16 +49,16 @@ RSpec.describe CaseLogsController, type: :controller do
let(:id) { case_log.id }
let(:case_log_form_params) do
{ accessibility_requirements:
%w[ accessibility_requirements_fully_wheelchair_accessible_housing
accessibility_requirements_wheelchair_access_to_essential_rooms
accessibility_requirements_level_access_housing],
page: "accessibility_requirements" }
%w[ housingneeds_a
housingneeds_b
housingneeds_c],
previous_page: "accessibility_requirements" }
end
let(:new_case_log_form_params) do
{
accessibility_requirements: %w[accessibility_requirements_level_access_housing],
page: "accessibility_requirements",
accessibility_requirements: %w[housingneeds_c],
previous_page: "accessibility_requirements",
}
end
@ -66,27 +66,27 @@ RSpec.describe CaseLogsController, type: :controller do
post :submit_form, params: { id: id, case_log: case_log_form_params }
case_log.reload
expect(case_log.accessibility_requirements_fully_wheelchair_accessible_housing).to eq(true)
expect(case_log.accessibility_requirements_wheelchair_access_to_essential_rooms).to eq(true)
expect(case_log.accessibility_requirements_level_access_housing).to eq(true)
expect(case_log.housingneeds_a).to eq(true)
expect(case_log.housingneeds_b).to eq(true)
expect(case_log.housingneeds_c).to eq(true)
end
it "sets previously submitted items to false when resubmitted with new values" do
post :submit_form, params: { id: id, case_log: new_case_log_form_params }
case_log.reload
expect(case_log.accessibility_requirements_fully_wheelchair_accessible_housing).to eq(false)
expect(case_log.accessibility_requirements_wheelchair_access_to_essential_rooms).to eq(false)
expect(case_log.accessibility_requirements_level_access_housing).to eq(true)
expect(case_log.housingneeds_a).to eq(false)
expect(case_log.housingneeds_b).to eq(false)
expect(case_log.housingneeds_c).to eq(true)
end
context "given a page with checkbox and non-checkbox questions" do
let(:tenant_code) { "BZ355" }
let(:case_log_form_params) do
{ accessibility_requirements:
%w[ accessibility_requirements_fully_wheelchair_accessible_housing
accessibility_requirements_wheelchair_access_to_essential_rooms
accessibility_requirements_level_access_housing],
%w[ housingneeds_a
housingneeds_b
housingneeds_c],
tenant_code: tenant_code,
page: "accessibility_requirements" }
end
@ -95,13 +95,13 @@ RSpec.describe CaseLogsController, type: :controller do
{
"type" => "checkbox",
"answer_options" =>
{ "accessibility_requirements_fully_wheelchair_accessible_housing" => "Fully wheelchair accessible housing",
"accessibility_requirements_wheelchair_access_to_essential_rooms" => "Wheelchair access to essential rooms",
"accessibility_requirements_level_access_housing" => "Level access housing",
"accessibility_requirements_other_disability_requirements" => "Other disability requirements",
"accessibility_requirements_no_disability_requirements" => "No disability requirements",
{ "housingneeds_a" => "Fully wheelchair accessible housing",
"housingneeds_b" => "Wheelchair access to essential rooms",
"housingneeds_c" => "Level access housing",
"housingneeds_f" => "Other disability requirements",
"housingneeds_g" => "No disability requirements",
"divider_a" => true,
"accessibility_requirements_do_not_know" => "Do not know",
"housingneeds_h" => "Do not know",
"divider_b" => true,
"accessibility_requirements_prefer_not_to_say" => "Prefer not to say" },
},
@ -116,9 +116,9 @@ RSpec.describe CaseLogsController, type: :controller do
post :submit_form, params: { id: id, case_log: case_log_form_params }
case_log.reload
expect(case_log.accessibility_requirements_fully_wheelchair_accessible_housing).to eq(true)
expect(case_log.accessibility_requirements_wheelchair_access_to_essential_rooms).to eq(true)
expect(case_log.accessibility_requirements_level_access_housing).to eq(true)
expect(case_log.housingneeds_a).to eq(true)
expect(case_log.housingneeds_b).to eq(true)
expect(case_log.housingneeds_c).to eq(true)
expect(case_log.tenant_code).to eq(tenant_code)
end
end
@ -130,15 +130,15 @@ RSpec.describe CaseLogsController, type: :controller do
let(:case_log_form_conditional_question_yes_params) do
{
pregnancy: "Yes",
page: "conditional_question",
preg_occ: "Yes",
previous_page: "conditional_question",
}
end
let(:case_log_form_conditional_question_no_params) do
{
pregnancy: "No",
page: "conditional_question",
preg_occ: "No",
previous_page: "conditional_question",
}
end
@ -170,7 +170,7 @@ RSpec.describe CaseLogsController, type: :controller do
it "returns a correct page path if there is conditional routing" do
responses_for_page = {}
responses_for_page["pregnancy"] = "No"
responses_for_page["preg_occ"] = "No"
expect(case_log_controller.send(:get_next_page_path, form, previous_conditional_page, responses_for_page)).to eq("case_log_conditional_question_no_page_path")
end
end

2
spec/factories/case_log.rb

@ -6,7 +6,7 @@ FactoryBot.define do
tenant_code { "TH356" }
property_postcode { "SW2 6HI" }
previous_postcode { "P0 5ST" }
person_1_age { "18" }
age1 { "12" }
end
trait :completed do
status { 2 }

131
spec/features/case_log_spec.rb

@ -6,24 +6,24 @@ RSpec.describe "Test Features" do
let(:status) { case_log.status }
question_answers = {
tenant_code: { type: "text", answer: "BZ737" },
person_1_age: { type: "numeric", answer: 25 },
person_1_gender: { type: "radio", answer: "Female" },
household_number_of_other_members: { type: "numeric", answer: 2 },
tenant_code: { type: "text", answer: "BZ737", path: "tenant_code" },
age1: { type: "numeric", answer: 25, path: "person_1_age" },
sex1: { type: "radio", answer: "Female", path: "person_1_gender" },
hhmemb: { type: "numeric", answer: 2, path: "household_number_of_other_members" },
}
def fill_in_number_question(case_log_id, question, value)
visit("/case_logs/#{case_log_id}/#{question}")
def fill_in_number_question(case_log_id, question, value, path)
visit("/case_logs/#{case_log_id}/#{path}")
fill_in("case-log-#{question.to_s.dasherize}-field", with: value)
click_button("Save and continue")
end
def answer_all_questions_in_income_subsection
visit("/case_logs/#{empty_case_log.id}/net_income")
fill_in("case-log-net-income-field", with: 18_000)
choose("case-log-net-income-frequency-yearly-field")
fill_in("case-log-earnings-field", with: 18_000)
choose("case-log-incfreq-yearly-field")
click_button("Save and continue")
choose("case-log-net-income-uc-proportion-all-field")
choose("case-log-benefits-all-field")
click_button("Save and continue")
choose("case-log-housing-benefit-housing-benefit-but-not-universal-credit-field")
click_button("Save and continue")
@ -84,65 +84,66 @@ RSpec.describe "Test Features" do
let(:case_log_with_checkbox_questions_answered) do
FactoryBot.create(
:case_log, :in_progress,
accessibility_requirements_fully_wheelchair_accessible_housing: true,
accessibility_requirements_level_access_housing: true
housingneeds_a: true,
housingneeds_c: true
)
end
context "Validate pregnancy questions" do
it "Cannot answer yes if no female tenants" do
expect {
CaseLog.create!(pregnancy: "Yes",
person_1_gender: "Male",
person_1_age: 20)
CaseLog.create!(preg_occ: "Yes",
sex1: "Male",
age1: 20)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "Cannot answer yes if no female tenants within age range" do
expect {
CaseLog.create!(pregnancy: "Yes",
person_1_gender: "Female",
person_1_age: 51)
CaseLog.create!(preg_occ: "Yes",
sex1: "Female",
age1: 51)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "Cannot answer prefer not to say if no valid tenants" do
expect {
CaseLog.create!(pregnancy: "Prefer not to say",
person_1_gender: "Male",
person_1_age: 20)
CaseLog.create!(preg_occ: "Prefer not to say",
sex1: "Male",
age1: 20)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "Can answer yes if valid tenants" do
expect {
CaseLog.create!(pregnancy: "Yes",
person_1_gender: "Female",
person_1_age: 20)
CaseLog.create!(preg_occ: "Yes",
sex1: "Female",
age1: 20)
}.not_to raise_error
end
it "Can answer yes if valid second tenant" do
expect {
CaseLog.create!(pregnancy: "Yes",
person_1_gender: "Male", person_1_age: 99,
person_2_gender: "Female",
person_2_age: 20)
CaseLog.create!(preg_occ: "Yes",
sex1: "Male", age1: 99,
sex2: "Female",
age2: 20)
}.not_to raise_error
end
end
it "can be accessed by url" do
visit("/case_logs/#{id}/person_1_age")
expect(page).to have_field("case-log-person-1-age-field")
expect(page).to have_field("case-log-age1-field")
end
it "updates model attributes correctly for each question" do
question_answers.each do |question, hsh|
type = hsh[:type]
answer = hsh[:answer]
path = hsh[:path]
original_value = case_log.send(question)
visit("/case_logs/#{id}/#{question}")
visit("/case_logs/#{id}/#{path}")
case type
when "text"
fill_in("case-log-#{question.to_s.dasherize}-field", with: answer)
@ -160,17 +161,17 @@ RSpec.describe "Test Features" do
it "updates total value of the rent", js: true do
visit("/case_logs/#{id}/rent")
fill_in("case-log-basic-rent-field", with: 3)
expect(page).to have_field("case-log-total-charge-field", with: "3")
fill_in("case-log-brent-field", with: 3)
expect(page).to have_field("case-log-tcharge-field", with: "3")
fill_in("case-log-service-charge-field", with: 2)
expect(page).to have_field("case-log-total-charge-field", with: "5")
fill_in("case-log-scharge-field", with: 2)
expect(page).to have_field("case-log-tcharge-field", with: "5")
fill_in("case-log-personal-service-charge-field", with: 1)
expect(page).to have_field("case-log-total-charge-field", with: "6")
fill_in("case-log-pscharge-field", with: 1)
expect(page).to have_field("case-log-tcharge-field", with: "6")
fill_in("case-log-support-charge-field", with: 4)
expect(page).to have_field("case-log-total-charge-field", with: "10")
fill_in("case-log-supcharge-field", with: 4)
expect(page).to have_field("case-log-tcharge-field", with: "10")
end
it "displays number answers in inputs if they are already saved" do
@ -180,22 +181,22 @@ RSpec.describe "Test Features" do
it "displays text answers in inputs if they are already saved" do
visit("/case_logs/#{id}/person_1_age")
expect(page).to have_field("case-log-person-1-age-field", with: "18")
expect(page).to have_field("case-log-age1-field", with: "12")
end
it "displays checkbox answers in inputs if they are already saved" do
visit("/case_logs/#{case_log_with_checkbox_questions_answered.id}/accessibility_requirements")
# Something about our styling makes the selenium webdriver think the actual radio buttons are not visible so we pass false here
expect(page).to have_checked_field(
"case-log-accessibility-requirements-accessibility-requirements-fully-wheelchair-accessible-housing-field",
"case-log-accessibility-requirements-housingneeds-a-field",
visible: false,
)
expect(page).to have_unchecked_field(
"case-log-accessibility-requirements-accessibility-requirements-wheelchair-access-to-essential-rooms-field",
"case-log-accessibility-requirements-housingneeds-b-field",
visible: false,
)
expect(page).to have_checked_field(
"case-log-accessibility-requirements-accessibility-requirements-level-access-housing-field",
"case-log-accessibility-requirements-housingneeds-c-field",
visible: false,
)
end
@ -222,7 +223,7 @@ RSpec.describe "Test Features" do
describe "Form flow is correct" do
context "given an ordered list of pages" do
it "leads to the next one in the correct order" do
pages = question_answers.keys
pages = question_answers.map {|_key, val| val[:path]}
pages[0..-2].each_with_index do |val, index|
visit("/case_logs/#{id}/#{val}")
click_button("Save and continue")
@ -253,7 +254,7 @@ RSpec.describe "Test Features" do
let(:last_question_for_subsection) { "household_number_of_other_members" }
it "redirects to the check answers page when answering the last question and clicking save and continue" do
fill_in_number_question(id, last_question_for_subsection, 0)
fill_in_number_question(id, "hhmemb", 0, last_question_for_subsection)
expect(page).to have_current_path("/case_logs/#{id}/#{subsection}/check_answers")
end
@ -266,8 +267,8 @@ RSpec.describe "Test Features" do
end
it "should display answers given by the user for the question in the subsection" do
fill_in_number_question(empty_case_log.id, "person_1_age", 28)
choose("case-log-person-1-gender-non-binary-field")
fill_in_number_question(empty_case_log.id, "age1", 28, "person_1_age")
choose("case-log-sex1-non-binary-field")
click_button("Save and continue")
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
expect(page).to have_content("28")
@ -282,7 +283,7 @@ RSpec.describe "Test Features" do
end
it "should have a change link for answered questions" do
fill_in_number_question(empty_case_log.id, "person_1_age", 28)
fill_in_number_question(empty_case_log.id, "age1", 28, "person_1_age")
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
assert_selector "a", text: /Answer\z/, count: 3
assert_selector "a", text: "Change", count: 1
@ -296,7 +297,7 @@ RSpec.describe "Test Features" do
end
it "should have a link pointing to the next empty question if some questions are answered" do
fill_in_number_question(empty_case_log.id, "net_income", 18_000)
fill_in_number_question(empty_case_log.id, "earnings", 18_000, "net_income")
visit("/case_logs/#{empty_case_log.id}/income_and_benefits/check_answers")
expect(page).to have_content("You answered 1 of 4 questions")
@ -324,7 +325,7 @@ RSpec.describe "Test Features" do
it "displays conditional question that were visited" do
visit("/case_logs/#{id}/conditional_question")
choose("case-log-pregnancy-no-field")
choose("case-log-preg-occ-no-field")
click_button("Save and continue")
visit("/case_logs/#{id}/#{conditional_subsection}/check_answers")
question_labels = ["Has the condition been met?", "Has the condition not been met?"]
@ -351,13 +352,13 @@ RSpec.describe "Test Features" do
visit("/case_logs/#{id}/armed_forces")
# Something about our styling makes the selenium webdriver think the actual radio buttons are not visible so we allow label click here
choose("case-log-armed-forces-yes-a-regular-field", allow_label_click: true)
expect(page).to have_selector("#armed_forces_injured_div")
choose("case-log-armed-forces-injured-no-field", allow_label_click: true)
expect(page).to have_checked_field("case-log-armed-forces-injured-no-field", visible: false)
expect(page).to have_selector("#reservist_div")
choose("case-log-reservist-no-field", allow_label_click: true)
expect(page).to have_checked_field("case-log-reservist-no-field", visible: false)
choose("case-log-armed-forces-no-field", allow_label_click: true)
expect(page).not_to have_selector("#armed_forces_injured_div")
expect(page).not_to have_selector("#reservist_div")
choose("case-log-armed-forces-yes-a-regular-field", allow_label_click: true)
expect(page).to have_unchecked_field("case-log-armed-forces-injured-no-field", visible: false)
expect(page).to have_unchecked_field("case-log-reservist-no-field", visible: false)
end
end
end
@ -366,18 +367,18 @@ RSpec.describe "Test Features" do
context "given an invalid tenant age" do
it " of less than 0 it shows validation" do
visit("/case_logs/#{id}/person_1_age")
fill_in_number_question(empty_case_log.id, "person_1_age", -5)
fill_in_number_question(empty_case_log.id, "age1", -5, "person_1_age")
expect(page).to have_selector("#error-summary-title")
expect(page).to have_selector("#case-log-person-1-age-error")
expect(page).to have_selector("#case-log-person-1-age-field-error")
expect(page).to have_selector("#case-log-age1-error")
expect(page).to have_selector("#case-log-age1-field-error")
end
it " of greater than 120 it shows validation" do
visit("/case_logs/#{id}/person_1_age")
fill_in_number_question(empty_case_log.id, "person_1_age", 121)
fill_in_number_question(empty_case_log.id, "age1", 121, "person_1_age")
expect(page).to have_selector("#error-summary-title")
expect(page).to have_selector("#case-log-person-1-age-error")
expect(page).to have_selector("#case-log-person-1-age-field-error")
expect(page).to have_selector("#case-log-age1-error")
expect(page).to have_selector("#case-log-age1-field-error")
end
end
end
@ -442,19 +443,21 @@ RSpec.describe "Test Features" do
it "can route the user to a different page based on their answer on the current page" do
visit("case_logs/#{id}/conditional_question")
choose("case-log-pregnancy-yes-field", allow_label_click: true)
# using a question name that is already in the db to avoid
# having to add a new column to the db for this test
choose("case-log-preg-occ-yes-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/case_logs/#{id}/conditional_question_yes_page")
click_link(text: "Back")
expect(page).to have_current_path("/case_logs/#{id}/conditional_question")
choose("case-log-pregnancy-no-field", allow_label_click: true)
choose("case-log-preg-occ-no-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/case_logs/#{id}/conditional_question_no_page")
end
it "can route based on page inclusion rules" do
visit("/case_logs/#{id}/conditional_question_yes_page")
choose("case-log-cbl-letting-yes-field", allow_label_click: true)
choose("case-log-cbl-yes-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/case_logs/#{id}/conditional_question/check_answers")
end
@ -467,10 +470,10 @@ RSpec.describe "Test Features" do
it "can route based on multiple conditions" do
visit("/case_logs/#{id}/person_1_gender")
choose("case-log-person-1-gender-female-field", allow_label_click: true)
choose("case-log-sex1-female-field", allow_label_click: true)
click_button("Save and continue")
visit("/case_logs/#{id}/conditional_question")
choose("case-log-pregnancy-yes-field", allow_label_click: true)
choose("case-log-preg-occ-yes-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/case_logs/#{id}/rent")
end

231
spec/fixtures/complete_case_log.json vendored

@ -1,118 +1,117 @@
{
"case_log":
{
"tenant_code": "T657",
"person_1_age": 35,
"person_1_gender": "Female",
"tenant_ethnic_group": "White: English/Scottish/Welsh/Northern Irish/British",
"tenant_nationality": "UK national resident in UK",
"previous_housing_situation": "Private sector tenancy",
"armed_forces": "Yes - a regular",
"person_1_economic_status": "Full-time - 30 hours or more",
"household_number_of_other_members": 7,
"person_2_relationship": "Partner",
"person_2_age": 32,
"person_2_gender": "Male",
"person_2_economic_status": "Not seeking work",
"person_3_relationship": "Child - includes young adult and grown-up",
"person_3_age": 12,
"person_3_gender": "Male",
"person_3_economic_status": "Child under 16",
"person_4_relationship": "Child - includes young adult and grown-up",
"person_4_age": 12,
"person_4_gender": "Female",
"person_4_economic_status": "Child under 16",
"person_5_relationship": "Child - includes young adult and grown-up",
"person_5_age": 10,
"person_5_gender": "Non-binary",
"person_5_economic_status": "Child under 16",
"person_6_relationship": "Child - includes young adult and grown-up",
"person_6_age": 5,
"person_6_gender": "Prefer not to say",
"person_6_economic_status": "Child under 16",
"person_7_relationship": "Child - includes young adult and grown-up",
"person_7_age": 5,
"person_7_gender": "Prefer not to say",
"person_7_economic_status": "Child under 16",
"person_8_relationship": "Child - includes young adult and grown-up",
"person_8_age": 2,
"person_8_gender": "Prefer not to say",
"person_8_economic_status": "Child under 16",
"homelessness": "Yes - other homelessness",
"reason_for_leaving_last_settled_home": "Other problems with neighbours",
"benefit_cap_spare_room_subsidy": "No",
"armed_forces_active": "No",
"armed_forces_injured": "No",
"armed_forces_partner": "No",
"medical_conditions": "Yes",
"pregnancy": "No",
"accessibility_requirements": "No",
"condition_effects": "dummy",
"tenancy_code": "BZ757",
"tenancy_start_date": "12/03/2019",
"starter_tenancy": "No",
"fixed_term_tenancy": "5",
"tenancy_type": "Fixed term – Secure",
"letting_type": "Affordable Rent - General Needs",
"letting_provider": "This landlord",
"property_location": "Barnet",
"previous_postcode": "NW1 5TY",
"property_relet": "No",
"property_vacancy_reason": "Relet - tenant abandoned property",
"property_reference": "P9876",
"property_unit_type": "House",
"property_building_type": "dummy",
"property_number_of_bedrooms": 3,
"property_void_date": "03/11/2019",
"property_major_repairs": "Yes",
"property_major_repairs_date": "05/05/2020",
"property_number_of_times_relet": 2,
"property_wheelchair_accessible": true,
"net_income_known": "Yes",
"net_income": 0,
"net_income_frequency": null,
"net_income_uc_proportion": "Some",
"housing_benefit": "Universal Credit with housing element, but not Housing Benefit",
"rent_frequency": "Weekly",
"basic_rent": 200,
"service_charge": 50,
"personal_service_charge": 40,
"support_charge": 35,
"total_charge": 325,
"outstanding_amount": "Yes",
"time_lived_in_la": "1 to 2 years",
"time_on_la_waiting_list": "Less than 1 year",
"previous_la": "Ashford",
"property_postcode": "SE2 6RT",
"reasonable_preference": "Yes",
"reasonable_preference_reason": "dummy",
"cbl_letting": true,
"chr_letting": false,
"cap_letting": false,
"outstanding_rent_or_charges": 25,
"other_reason_for_leaving_last_settled_home": null,
"accessibility_requirements_fully_wheelchair_accessible_housing": true,
"accessibility_requirements_wheelchair_access_to_essential_rooms": false,
"accessibility_requirements_level_access_housing": false,
"accessibility_requirements_other_disability_requirements": false,
"accessibility_requirements_no_disability_requirements": false,
"accessibility_requirements_do_not_know": false,
"accessibility_requirements_prefer_not_to_say": false,
"condition_effects_vision": false,
"condition_effects_hearing": true,
"condition_effects_mobility": false,
"condition_effects_dexterity": false,
"condition_effects_stamina": false,
"condition_effects_learning": false,
"condition_effects_memory": false,
"condition_effects_mental_health": false,
"condition_effects_social_or_behavioral": false,
"condition_effects_other": false,
"condition_effects_prefer_not_to_say": true,
"reasonable_preference_reason_homeless": false,
"reasonable_preference_reason_unsatisfactory_housing": false,
"reasonable_preference_reason_medical_grounds": false,
"reasonable_preference_reason_avoid_hardship": false,
"reasonable_preference_reason_do_not_know": true
}
"case_log": {
"tenant_code": "T657",
"age1": 35,
"sex1": "Female",
"ethnic": "White: English/Scottish/Welsh/Northern Irish/British",
"national": "UK national resident in UK",
"prevten": "Private sector tenancy",
"armed_forces": "Yes - a regular",
"ecstat1": "Full-time - 30 hours or more",
"hhmemb": 7,
"relat2": "Partner",
"age2": 32,
"sex2": "Male",
"ecstat2": "Not seeking work",
"relat3": "Child - includes young adult and grown-up",
"age3": 12,
"sex3": "Male",
"ecstat3": "Child under 16",
"relat4": "Child - includes young adult and grown-up",
"age4": 12,
"sex4": "Female",
"ecstat4": "Child under 16",
"relat5": "Child - includes young adult and grown-up",
"age5": 10,
"sex5": "Non-binary",
"ecstat5": "Child under 16",
"relat6": "Child - includes young adult and grown-up",
"age6": 5,
"sex6": "Prefer not to say",
"ecstat6": "Child under 16",
"relat7": "Child - includes young adult and grown-up",
"age7": 5,
"sex7": "Prefer not to say",
"ecstat7": "Child under 16",
"relat8": "Child - includes young adult and grown-up",
"age8": 2,
"sex8": "Prefer not to say",
"ecstat8": "Child under 16",
"homeless": "Yes - other homelessness",
"reason_for_leaving_last_settled_home": "Other problems with neighbours",
"underoccupation_benefitcap": "No",
"leftreg": "No",
"reservist": "No",
"armed_forces_partner": "No",
"illness": "Yes",
"preg_occ": "No",
"accessibility_requirements": "No",
"condition_effects": "dummy",
"tenancy_code": "BZ757",
"startdate": "12/03/2019",
"startertenancy": "No",
"tenancylength": "5",
"tenancy": "Fixed term – Secure",
"lettype": "Affordable Rent - General Needs",
"landlord": "This landlord",
"property_location": "Barnet",
"previous_postcode": "NW1 5TY",
"property_relet": "No",
"rsnvac": "Relet - tenant abandoned property",
"property_reference": "P9876",
"unittype_gn": "House",
"property_building_type": "dummy",
"beds": 3,
"property_void_date": "03/11/2019",
"property_major_repairs": "Yes",
"property_major_repairs_date": "05/05/2020",
"offered": 2,
"wchair": true,
"net_income_known": "Yes",
"earnings": 0,
"incfreq": null,
"benefits": "Some",
"housing_benefit": "Universal Credit with housing element, but not Housing Benefit",
"period": "Weekly",
"brent": 200,
"scharge": 50,
"pscharge": 40,
"supcharge": 35,
"tcharge": 325,
"outstanding_amount": "Yes",
"layear": "1 to 2 years",
"lawaitlist": "Less than 1 year",
"previous_la": "Ashford",
"property_postcode": "SE2 6RT",
"reasonpref": "Yes",
"reasonable_preference_reason": "dummy",
"cbl": true,
"chr": false,
"cap": false,
"outstanding_rent_or_charges": 25,
"other_reason_for_leaving_last_settled_home": null,
"housingneeds_a": true,
"housingneeds_b": false,
"housingneeds_c": false,
"housingneeds_f": false,
"housingneeds_g": false,
"housingneeds_h": false,
"accessibility_requirements_prefer_not_to_say": false,
"illness_type_1": false,
"illness_type_2": true,
"illness_type_3": false,
"illness_type_4": false,
"illness_type_8": false,
"illness_type_5": false,
"illness_type_6": false,
"illness_type_7": false,
"illness_type_9": false,
"illness_type_10": false,
"condition_effects_prefer_not_to_say": true,
"rp_homeless": false,
"rp_insan_unsat": false,
"rp_medwel": false,
"rp_hardship": false,
"rp_dontknow": true
}
}

122
spec/fixtures/forms/test_form.json vendored

@ -18,7 +18,7 @@
},
"person_1_age": {
"questions": {
"person_1_age": {
"age1": {
"check_answer_label": "Tenant's age",
"header": "What is the tenant's age?",
"type": "numeric",
@ -30,7 +30,7 @@
},
"person_1_gender": {
"questions": {
"person_1_gender": {
"sex1": {
"check_answer_label": "Tenant's gender",
"header": "Which of these best describes the tenant's gender identity?",
"type": "radio",
@ -45,7 +45,7 @@
},
"household_number_of_other_members": {
"questions": {
"household_number_of_other_members": {
"hhmemb": {
"check_answer_label": "Number of Other Household Members",
"header": "How many other people are there in the household?",
"hint_text": "The maximum number of others is 1",
@ -54,13 +54,13 @@
"max": 1,
"step": 1,
"conditional_for": {
"person_2_relationship": ">0",
"person_2_age": ">0",
"person_2_gender": ">0",
"person_2_economic_status": ">0"
"relat2": ">0",
"age2": ">0",
"sex2": ">0",
"ecstat2": ">0"
}
},
"person_2_relationship": {
"relat2": {
"check_answer_label": "Person 2's relationship to lead tenant",
"header": "What's person 2's relationship to lead tenant",
"type": "radio",
@ -69,7 +69,7 @@
"1": "Prefer not to say"
}
},
"person_2_age": {
"age2": {
"check_answer_label": "Person 2's age",
"header": "What's person 2's age",
"type": "numeric",
@ -77,7 +77,7 @@
"max": 150,
"step": 1
},
"person_2_gender": {
"sex2": {
"check_answer_label": "Person 2's gender",
"header": "Which of these best describes person 2's gender identity?",
"type": "radio",
@ -88,7 +88,7 @@
"3": "Prefer not to say"
}
},
"person_2_economic_status": {
"ecstat2": {
"check_answer_label": "Person 2's Work",
"header": "Which of these best describes person 2's working situation?",
"type": "radio",
@ -118,17 +118,11 @@
"3": "Prefer not to say"
},
"conditional_for": {
"armed_forces_active": [
"Yes - a regular",
"Yes - a reserve"
],
"armed_forces_injured": [
"Yes - a regular",
"Yes - a reserve"
]
"leftreg": ["Yes - a regular", "Yes - a reserve"],
"reservist": ["Yes - a regular", "Yes - a reserve"]
}
},
"armed_forces_active": {
"leftreg": {
"header": "Are they still serving?",
"type": "radio",
"check_answer_label": "When did they leave the Armed Forces?",
@ -139,7 +133,7 @@
"3": "Prefer not to say"
}
},
"armed_forces_injured": {
"reservist": {
"header": "Were they seriously injured or ill as a result of their service?",
"type": "radio",
"check_answer_label": "Has anyone in the household been seriously injured or ill as a result of their service in the armed forces?",
@ -153,7 +147,7 @@
},
"medical_conditions": {
"questions": {
"medical_conditions": {
"illness": {
"header": "Does anyone in the household have any of the following that they expect to last for 12 months or more:<ul><li>Physical Condition</li><li>Mental Health Condition</li><li>Other Illness</li></ul>",
"type": "radio",
"check_answer_label": "Physical, mental health or illness in the household",
@ -174,11 +168,11 @@
"type": "checkbox",
"check_answer_label": "Disability requirements",
"answer_options": {
"accessibility_requirements_fully_wheelchair_accessible_housing": "Fully wheelchair accessible housing",
"accessibility_requirements_wheelchair_access_to_essential_rooms": "Wheelchair access to essential rooms",
"accessibility_requirements_level_access_housing": "Level access housing",
"housingneeds_a": "Fully wheelchair accessible housing",
"housingneeds_b": "Wheelchair access to essential rooms",
"housingneeds_c": "Level access housing",
"divider_a": true,
"accessibility_requirements_do_not_know": "Do not know"
"housingneeds_h": "Do not know"
}
}
}
@ -191,8 +185,8 @@
"type": "checkbox",
"check_answer_label": "Conditions or illnesses",
"answer_options": {
"condition_effects_vision": "Vision - such as blindness or partial sight",
"condition_effects_hearing": "Hearing - such as deafness or partial hearing"
"illness_type_1": "Vision - such as blindness or partial sight",
"illness_type_2": "Hearing - such as deafness or partial hearing"
}
}
}
@ -223,7 +217,7 @@
"pages": {
"property_wheelchair_accessible": {
"questions": {
"property_wheelchair_accessible": {
"wchair": {
"check_answer_label": "Is property built or adapted to wheelchair user standards?",
"header": "Is property built or adapted to wheelchair user standards?",
"type": "radio",
@ -241,7 +235,7 @@
"pages": {
"conditional_question": {
"questions": {
"pregnancy": {
"preg_occ": {
"check_answer_label": "Has the condition been met?",
"header": "Has the condition been met?",
"type": "radio",
@ -252,15 +246,15 @@
}
},
"conditional_route_to": {
"rent": { "pregnancy": "Yes", "person_1_gender": "Female" },
"conditional_question_yes_page": { "pregnancy": "Yes" },
"conditional_question_no_page": { "pregnancy": "No" }
"rent": { "preg_occ": "Yes", "sex1": "Female" },
"conditional_question_yes_page": { "preg_occ": "Yes" },
"conditional_question_no_page": { "preg_occ": "No" }
},
"default_next_page": "check_answers"
},
"conditional_question_yes_page": {
"questions": {
"cbl_letting": {
"cbl": {
"check_answer_label": "Has the next condition been met?",
"header": "Has the next condition been met?",
"type": "radio",
@ -311,14 +305,14 @@
"pages": {
"net_income": {
"questions": {
"net_income": {
"earnings": {
"check_answer_label": "Income",
"header": "What is the tenant’s /and partner’s combined income after tax?",
"type": "numeric",
"min": 0,
"step": "1"
},
"net_income_frequency": {
"incfreq": {
"check_answer_label": "Income Frequency",
"header": "How often do they receive this income?",
"type": "radio",
@ -341,7 +335,7 @@
},
"net_income_uc_proportion": {
"questions": {
"net_income_uc_proportion": {
"benefits": {
"check_answer_label": "Benefits as a proportion of income",
"header": "How much of the tenant’s income is from Universal Credit, state pensions or benefits?",
"type": "radio",
@ -381,7 +375,7 @@
"1": "Fortnightly"
}
},
"basic_rent": {
"brent": {
"check_answer_label": "Basic Rent",
"header": "What is the basic rent?",
"hint_text": "Eligible for housing benefit or Universal Credit",
@ -389,14 +383,14 @@
"min": 0,
"step": 1,
"fields-to-add": [
"basic_rent",
"service_charge",
"personal_service_charge",
"support_charge"
"brent",
"scharge",
"pscharge",
"supcharge"
],
"result-field": "total_charge"
"result-field": "tcharge"
},
"service_charge": {
"scharge": {
"check_answer_label": "Service Charge",
"header": "What is the service charge?",
"hint_text": "Eligible for housing benefit or Universal Credit",
@ -404,14 +398,14 @@
"min": 0,
"step": 1,
"fields-to-add": [
"basic_rent",
"service_charge",
"personal_service_charge",
"support_charge"
"brent",
"scharge",
"pscharge",
"supcharge"
],
"result-field": "total_charge"
"result-field": "tcharge"
},
"personal_service_charge": {
"pscharge": {
"check_answer_label": "Personal Service Charge",
"header": "What is the personal service charge?",
"hint_text": "Not eligible for housing benefit or Universal Credit. For example, hot water excluding water rates.",
@ -419,14 +413,14 @@
"min": 0,
"step": 1,
"fields-to-add": [
"basic_rent",
"service_charge",
"personal_service_charge",
"support_charge"
"brent",
"scharge",
"pscharge",
"supcharge"
],
"result-field": "total_charge"
"result-field": "tcharge"
},
"support_charge": {
"supcharge": {
"check_answer_label": "Support Charge",
"header": "What is the support charge?",
"hint_text": "This is to fund housing-related support services included in the tenancy agreement",
@ -434,14 +428,14 @@
"min": 0,
"step": 1,
"fields-to-add": [
"basic_rent",
"service_charge",
"personal_service_charge",
"support_charge"
"brent",
"scharge",
"pscharge",
"supcharge"
],
"result-field": "total_charge"
"result-field": "tcharge"
},
"total_charge": {
"tcharge": {
"check_answer_label": "Total Charge",
"header": "Total charge?",
"hint_text": "This is the total of rent and all charges",
@ -464,7 +458,7 @@
"pages": {
"time_lived_in_la": {
"questions": {
"time_lived_in_la": {
"layear": {
"check_answer_label": "How long has the household continuously lived in the local authority area where the new letting is located?",
"header": "How long has the household continuously lived in the local authority area where the new letting is located?",
"type": "radio",
@ -483,7 +477,7 @@
},
"time_on_la_waiting_list": {
"questions": {
"time_on_la_waiting_list": {
"lawaitlist": {
"check_answer_label": "How long has the household been on the local authority waiting list where the new letting is located?",
"header": "How long has the household been on the local authority waiting list where the new letting is located?",
"type": "radio",

36
spec/helpers/check_answers_helper_spec.rb

@ -6,14 +6,14 @@ RSpec.describe CheckAnswersHelper do
FactoryBot.create(
:case_log,
:in_progress,
household_number_of_other_members: 1,
person_2_relationship: "Partner",
hhmemb: 1,
relat2: "Partner",
)
end
let(:case_log_with_met_radio_condition) do
FactoryBot.create(:case_log, armed_forces: "Yes - a regular",
armed_forces_injured: "No",
armed_forces_active: "Yes")
reservist: "No",
leftreg: "Yes")
end
let(:subsection) { "income_and_benefits" }
let(:subsection_with_numeric_conditionals) { "household_characteristics" }
@ -29,7 +29,7 @@ RSpec.describe CheckAnswersHelper do
end
it "returns 1 if 1 question gets answered" do
case_log["net_income"] = "123"
case_log["earnings"] = "123"
expect(total_answered_questions(subsection, case_log, form)).to equal(1)
end
@ -52,8 +52,8 @@ RSpec.describe CheckAnswersHelper do
end
it "includes conditional questions with met radio conditions" do
case_log_with_met_radio_condition["armed_forces_injured"] = "No"
case_log_with_met_radio_condition["medical_conditions"] = "No"
case_log_with_met_radio_condition["reservist"] = "No"
case_log_with_met_radio_condition["illness"] = "No"
expect(total_answered_questions(
subsection_with_radio_conditionals,
case_log_with_met_radio_condition,
@ -113,12 +113,12 @@ RSpec.describe CheckAnswersHelper do
end
it "counts correct questions when the conditional question is answered" do
case_log["pregnancy"] = "Yes"
case_log["preg_occ"] = "Yes"
expect(total_number_of_questions(conditional_routing_subsection, case_log, form)).to eq(2)
end
it "counts correct questions when the conditional question is answered" do
case_log["pregnancy"] = "No"
case_log["preg_occ"] = "No"
expect(total_number_of_questions(conditional_routing_subsection, case_log, form)).to eq(3)
end
end
@ -127,21 +127,21 @@ RSpec.describe CheckAnswersHelper do
it "returns total questions" do
result = total_questions(subsection, case_log, form)
expect(result.class).to eq(Hash)
expected_keys = %w[net_income net_income_frequency net_income_uc_proportion housing_benefit]
expected_keys = %w[earnings incfreq benefits housing_benefit]
expect(result.keys).to eq(expected_keys)
end
context "conditional questions on the same page" do
it "it filters out conditional questions that were not displayed" do
result = total_questions(conditional_page_subsection, case_log, form)
expected_keys = %w[armed_forces medical_conditions accessibility_requirements condition_effects]
expected_keys = %w[armed_forces illness accessibility_requirements condition_effects]
expect(result.keys).to eq(expected_keys)
end
it "it includes conditional questions that were displayed" do
case_log["armed_forces"] = "Yes - a regular"
result = total_questions(conditional_page_subsection, case_log, form)
expected_keys = %w[armed_forces armed_forces_active armed_forces_injured medical_conditions accessibility_requirements condition_effects]
expected_keys = %w[armed_forces leftreg reservist illness accessibility_requirements condition_effects]
expect(result.keys).to eq(expected_keys)
end
end
@ -149,22 +149,22 @@ RSpec.describe CheckAnswersHelper do
context "conditional routing" do
it "it ignores skipped pages and the questions therein when conditional routing" do
result = total_questions(conditional_routing_subsection, case_log, form)
expected_keys = %w[pregnancy]
expected_keys = %w[preg_occ]
expect(result.keys).to match_array(expected_keys)
end
it "it includes conditional pages and questions that were displayed" do
case_log["pregnancy"] = "Yes"
case_log["person_1_gender"] = "Female"
case_log["preg_occ"] = "Yes"
case_log["sex1"] = "Female"
result = total_questions(conditional_routing_subsection, case_log, form)
expected_keys = %w[pregnancy]
expected_keys = %w[preg_occ]
expect(result.keys).to match_array(expected_keys)
end
it "it includes conditional pages and questions that were displayed" do
case_log["pregnancy"] = "No"
case_log["preg_occ"] = "No"
result = total_questions(conditional_routing_subsection, case_log, form)
expected_keys = %w[pregnancy conditional_question_no_question conditional_question_no_second_question]
expected_keys = %w[preg_occ conditional_question_no_question conditional_question_no_second_question]
expect(result.keys).to match_array(expected_keys)
end
end

4
spec/helpers/conditional_questions_helper_spec.rb

@ -7,7 +7,7 @@ RSpec.describe ConditionalQuestionsHelper do
let(:page) { form.all_pages[page_key] }
describe "conditional questions for page" do
let(:conditional_pages) { %w[armed_forces_active armed_forces_injured] }
let(:conditional_pages) { %w[leftreg reservist] }
it "returns the question keys of all conditional questions on the given page" do
expect(conditional_questions_for_page(page)).to eq(conditional_pages)
@ -16,7 +16,7 @@ RSpec.describe ConditionalQuestionsHelper do
describe "display question key div" do
let(:question_key) { "armed_forces" }
let(:conditional_question_key) { "armed_forces_injured" }
let(:conditional_question_key) { "reservist" }
it "returns a non visible div for conditional questions" do
expect(display_question_key_div(page, conditional_question_key)).to match("style='display:none;'")

12
spec/helpers/question_attribute_helper_spec.rb

@ -7,15 +7,15 @@ RSpec.describe QuestionAttributeHelper do
describe "html attributes" do
it "returns empty hash if fields-to-add or result-field are empty " do
expect(stimulus_html_attributes(questions["total_charge"])).to eq({})
expect(stimulus_html_attributes(questions["tcharge"])).to eq({})
end
it "returns html attributes if fields-to-add or result-field are not empty " do
expect(stimulus_html_attributes(questions["basic_rent"])).to eq({
expect(stimulus_html_attributes(questions["brent"])).to eq({
"data-controller": "numeric-question",
"data-action": "numeric-question#calculateFields",
"data-target": "case-log-#{questions['basic_rent']['result-field'].to_s.dasherize}-field",
"data-calculated": questions["basic_rent"]["fields-to-add"].to_json,
"data-target": "case-log-#{questions['brent']['result-field'].to_s.dasherize}-field",
"data-calculated": questions["brent"]["fields-to-add"].to_json,
})
end
@ -28,8 +28,8 @@ RSpec.describe QuestionAttributeHelper do
"type" => "numeric",
"min" => 0,
"step" => 1,
"fields-to-add" => %w[basic_rent service_charge personal_service_charge support_charge],
"result-field" => "total_charge",
"fields-to-add" => %w[brent scharge pscharge supcharge],
"result-field" => "tcharge",
"conditional_for" => {
"next_question": ">1",
},

2
spec/helpers/tasklist_helper_spec.rb

@ -30,7 +30,7 @@ RSpec.describe TasklistHelper do
end
it "returns completed if all the questions in the subsection have been answered" do
%w[net_income net_income_frequency net_income_uc_proportion housing_benefit].each { |x| case_log[x] = "value" }
%w[earnings incfreq benefits housing_benefit].each { |x| case_log[x] = "value" }
status = get_subsection_status("income_and_benefits", case_log, income_and_benefits_questions)
expect(status).to eq(:completed)
end

146
spec/models/case_log_spec.rb

@ -3,46 +3,46 @@ require "rails_helper"
RSpec.describe Form, type: :model do
describe "#new" do
it "validates age is a number" do
expect { CaseLog.create!(person_1_age: "random") }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(age1: "random") }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validates age is under 120" do
expect { CaseLog.create!(person_1_age: 121) }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(age1: 121) }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validates age is over 0" do
expect { CaseLog.create!(person_1_age: 0) }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(age1: 0) }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validates number of relets is a number" do
expect { CaseLog.create!(property_number_of_times_relet: "random") }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(offered: "random") }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validates number of relets is under 20" do
expect { CaseLog.create!(property_number_of_times_relet: 21) }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(offered: 21) }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validates number of relets is over 0" do
expect { CaseLog.create!(property_number_of_times_relet: 0) }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(offered: 0) }.to raise_error(ActiveRecord::RecordInvalid)
end
context "reasonable preference validation" do
it "if given reasonable preference is yes a reason must be selected" do
expect {
CaseLog.create!(reasonable_preference: "Yes",
reasonable_preference_reason_homeless: nil,
reasonable_preference_reason_unsatisfactory_housing: nil,
reasonable_preference_reason_medical_grounds: nil,
reasonable_preference_reason_avoid_hardship: nil,
reasonable_preference_reason_do_not_know: nil)
CaseLog.create!(reasonpref: "Yes",
rp_homeless: nil,
rp_insan_unsat: nil,
rp_medwel: nil,
rp_hardship: nil,
rp_dontknow: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "if not previously homeless reasonable preference should not be selected" do
expect {
CaseLog.create!(
homelessness: "No",
reasonable_preference: "Yes",
homeless: "No",
reasonpref: "Yes",
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
@ -50,9 +50,9 @@ RSpec.describe Form, type: :model do
it "if not given reasonable preference a reason should not be selected" do
expect {
CaseLog.create!(
homelessness: "Yes",
reasonable_preference: "No",
reasonable_preference_reason_homeless: true,
homeless: "Yes",
reasonpref: "No",
rp_homeless: true,
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
@ -61,7 +61,7 @@ RSpec.describe Form, type: :model do
it "Reason for leaving must be don't know if reason for leaving settled home (Q9a) is don't know." do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Do not know",
benefit_cap_spare_room_subsidy: "Yes - benefit cap")
underoccupation_benefitcap: "Yes - benefit cap")
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
@ -85,14 +85,14 @@ RSpec.describe Form, type: :model do
it "must be answered if tenant was a regular or reserve in armed forces" do
expect {
CaseLog.create!(armed_forces: "Yes - a regular",
armed_forces_injured: nil)
reservist: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must be answered if tenant was not a regular or reserve in armed forces" do
expect {
CaseLog.create!(armed_forces: "No",
armed_forces_injured: "Yes")
reservist: "Yes")
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
@ -100,38 +100,38 @@ RSpec.describe Form, type: :model do
context "Shared accomodation bedrooms validation" do
it "you must have more than zero bedrooms" do
expect {
CaseLog.create!(property_unit_type: "Shared house",
property_number_of_bedrooms: 0)
CaseLog.create!(unittype_gn: "Shared house",
beds: 0)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "you must answer less than 8 bedrooms" do
expect {
CaseLog.create!(property_unit_type: "Shared bungalow",
property_number_of_bedrooms: 8,
household_number_of_other_members: 1)
CaseLog.create!(unittype_gn: "Shared bungalow",
beds: 8,
hhmemb: 1)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "you must answer less than 8 bedrooms" do
expect {
CaseLog.create!(property_unit_type: "Shared bungalow",
property_number_of_bedrooms: 4,
household_number_of_other_members: 0)
CaseLog.create!(unittype_gn: "Shared bungalow",
beds: 4,
hhmemb: 0)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "A bedsit must only have one room" do
expect {
CaseLog.create!(property_unit_type: "Bed-sit",
property_number_of_bedrooms: 2)
CaseLog.create!(unittype_gn: "Bed-sit",
beds: 2)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "A bedsit must only have one room" do
expect {
CaseLog.create!(property_unit_type: "Bed-sit",
property_number_of_bedrooms: 0)
CaseLog.create!(unittype_gn: "Bed-sit",
beds: 0)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
@ -155,19 +155,19 @@ RSpec.describe Form, type: :model do
context "tenant’s income is from Universal Credit, state pensions or benefits" do
it "Cannot be All if person 1 works full time" do
expect {
CaseLog.create!(net_income_uc_proportion: "All", person_1_economic_status: "Full-time - 30 hours or more")
CaseLog.create!(benefits: "All", ecstat1: "Full-time - 30 hours or more")
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "Cannot be All if person 1 works part time" do
expect {
CaseLog.create!(net_income_uc_proportion: "All", person_1_economic_status: "Part-time - Less than 30 hours")
CaseLog.create!(benefits: "All", ecstat1: "Part-time - Less than 30 hours")
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "Cannot be 1 All if any of persons 2-4 are person 1's partner and work part or full time" do
expect {
CaseLog.create!(net_income_uc_proportion: "All", person_2_relationship: "Partner", person_2_economic_status: "Part-time - Less than 30 hours")
CaseLog.create!(benefits: "All", relat2: "Partner", ecstat2: "Part-time - Less than 30 hours")
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
@ -175,47 +175,47 @@ RSpec.describe Form, type: :model do
context "fixed term tenancy length" do
it "Must not be completed if Type of main tenancy is not responded with either Secure or Assured shorthold " do
expect {
CaseLog.create!(tenancy_type: "Other",
fixed_term_tenancy: 10)
CaseLog.create!(tenancy: "Other",
tenancylength: 10)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "Must be completed and between 2 and 99 if type of tenancy is Assured shorthold" do
expect {
CaseLog.create!(tenancy_type: "Fixed term – Assured Shorthold Tenancy (AST)",
fixed_term_tenancy: 1)
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)",
tenancylength: 1)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy_type: "Fixed term – Assured Shorthold Tenancy (AST)",
fixed_term_tenancy: nil)
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)",
tenancylength: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy_type: "Fixed term – Assured Shorthold Tenancy (AST)",
fixed_term_tenancy: 2)
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)",
tenancylength: 2)
}.not_to raise_error
end
it "Must be empty or between 2 and 99 if type of tenancy is Secure" do
expect {
CaseLog.create!(tenancy_type: "Fixed term – Secure",
fixed_term_tenancy: 1)
CaseLog.create!(tenancy: "Fixed term – Secure",
tenancylength: 1)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy_type: "Fixed term – Secure",
fixed_term_tenancy: 100)
CaseLog.create!(tenancy: "Fixed term – Secure",
tenancylength: 100)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy_type: "Fixed term – Secure",
fixed_term_tenancy: nil)
CaseLog.create!(tenancy: "Fixed term – Secure",
tenancylength: nil)
}.not_to raise_error
expect {
CaseLog.create!(tenancy_type: "Fixed term – Secure",
fixed_term_tenancy: 2)
CaseLog.create!(tenancy: "Fixed term – Secure",
tenancylength: 2)
}.not_to raise_error
end
end
@ -224,14 +224,14 @@ RSpec.describe Form, type: :model do
it "must be answered if ever served in the forces as a regular" do
expect {
CaseLog.create!(armed_forces: "Yes - a regular",
armed_forces_active: nil)
leftreg: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must not be answered if not ever served as a regular" do
expect {
CaseLog.create!(armed_forces: "No",
armed_forces_active: "Yes")
leftreg: "Yes")
}.to raise_error(ActiveRecord::RecordInvalid)
end
@ -239,8 +239,8 @@ RSpec.describe Form, type: :model do
it "must be answered if ever served in the forces as a regular" do
expect do
CaseLog.create!(armed_forces: "Yes - a regular",
armed_forces_active: "Yes",
armed_forces_injured: "Yes")
leftreg: "Yes",
reservist: "Yes")
end
end
end
@ -282,25 +282,25 @@ RSpec.describe Form, type: :model do
context "other tenancy type validation" do
it "must be provided if tenancy type was given as other" do
expect {
CaseLog.create!(tenancy_type: "Other",
other_tenancy_type: nil)
CaseLog.create!(tenancy: "Other",
tenancyother: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy_type: "Other",
other_tenancy_type: "type")
CaseLog.create!(tenancy: "Other",
tenancyother: "type")
}.not_to raise_error
end
it "must not be provided if tenancy type is not other" do
expect {
CaseLog.create!(tenancy_type: "Fixed",
other_tenancy_type: "the other reason provided")
CaseLog.create!(tenancy: "Fixed",
tenancyother: "the other reason provided")
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy_type: "Fixed",
other_tenancy_type: nil)
CaseLog.create!(tenancy: "Fixed",
tenancyother: nil)
}.not_to raise_error
end
end
@ -309,9 +309,9 @@ RSpec.describe Form, type: :model do
it "validates net income maximum" do
expect {
CaseLog.create!(
person_1_economic_status: "Full-time - 30 hours or more",
net_income: 5000,
net_income_frequency: "Weekly",
ecstat1: "Full-time - 30 hours or more",
earnings: 5000,
incfreq: "Weekly",
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
@ -319,9 +319,9 @@ RSpec.describe Form, type: :model do
it "validates net income minimum" do
expect {
CaseLog.create!(
person_1_economic_status: "Full-time - 30 hours or more",
net_income: 1,
net_income_frequency: "Weekly",
ecstat1: "Full-time - 30 hours or more",
earnings: 1,
incfreq: "Weekly",
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
@ -347,20 +347,20 @@ RSpec.describe Form, type: :model do
describe "weekly_net_income" do
let(:net_income) { 5000 }
let(:case_log) { FactoryBot.build(:case_log, net_income: net_income) }
let(:case_log) { FactoryBot.build(:case_log, earnings: net_income) }
it "returns input income if frequency is already weekly" do
case_log.net_income_frequency = "Weekly"
case_log.incfreq = "Weekly"
expect(case_log.weekly_net_income).to eq(net_income)
end
it "calculates the correct weekly income from monthly income" do
case_log.net_income_frequency = "Monthly"
case_log.incfreq = "Monthly"
expect(case_log.weekly_net_income).to eq(1154)
end
it "calculates the correct weekly income from yearly income" do
case_log.net_income_frequency = "Yearly"
case_log.incfreq = "Yearly"
expect(case_log.weekly_net_income).to eq(417)
end
end

2
spec/models/form_spec.rb

@ -39,7 +39,7 @@ RSpec.describe Form, type: :model do
it "returns all questions for subsection" do
result = form.questions_for_subsection(subsection)
expect(result.length).to eq(4)
expect(result.keys).to eq(%w[net_income net_income_frequency net_income_uc_proportion housing_benefit])
expect(result.keys).to eq(%w[earnings incfreq benefits housing_benefit])
end
end
end

20
spec/requests/case_log_controller_spec.rb

@ -24,8 +24,8 @@ RSpec.describe CaseLogsController, type: :request do
describe "POST #create" do
let(:tenant_code) { "T365" }
let(:person_1_age) { 35 }
let(:property_number_of_times_relet) { 12 }
let(:age1) { 35 }
let(:offered) { 12 }
let(:property_postcode) { "SE11 6TY" }
let(:in_progress) { "in_progress" }
let(:completed) { "completed" }
@ -33,9 +33,9 @@ RSpec.describe CaseLogsController, type: :request do
let(:params) do
{
"tenant_code": tenant_code,
"person_1_age": person_1_age,
"age1": age1,
"property_postcode": property_postcode,
"property_number_of_times_relet": property_number_of_times_relet,
"offered": offered,
}
end
@ -55,18 +55,18 @@ RSpec.describe CaseLogsController, type: :request do
it "creates a case log with the values passed" do
json_response = JSON.parse(response.body)
expect(json_response["tenant_code"]).to eq(tenant_code)
expect(json_response["person_1_age"]).to eq(person_1_age)
expect(json_response["age1"]).to eq(age1)
expect(json_response["property_postcode"]).to eq(property_postcode)
end
context "invalid json params" do
let(:person_1_age) { 2000 }
let(:property_number_of_times_relet) { 21 }
let(:age1) { 2000 }
let(:offered) { 21 }
it "validates case log parameters" do
json_response = JSON.parse(response.body)
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response["errors"]).to match_array([["property_number_of_times_relet", ["Property number of times relet must be between 0 and 20"]], ["person_1_age", ["Tenant age must be an integer between 16 and 120"]]])
expect(json_response["errors"]).to match_array([["offered", ["Property number of times relet must be between 0 and 20"]], ["age1", ["Tenant age must be an integer between 16 and 120"]]])
end
end
@ -157,7 +157,7 @@ RSpec.describe CaseLogsController, type: :request do
end
context "invalid case log params" do
let(:params) { { person_1_age: 200 } }
let(:params) { { age1: 200 } }
it "returns 422" do
expect(response).to have_http_status(:unprocessable_entity)
@ -165,7 +165,7 @@ RSpec.describe CaseLogsController, type: :request do
it "returns an error message" do
json_response = JSON.parse(response.body)
expect(json_response["errors"]).to eq({ "person_1_age" => ["Tenant age must be an integer between 16 and 120"] })
expect(json_response["errors"]).to eq({ "age1" => ["Tenant age must be an integer between 16 and 120"] })
end
end

Loading…
Cancel
Save