Browse Source

Db migration (#79)

* migration wip

* change field names to lowercase and fix the tests

* Change national and ethnic field types and map to correct enums

* change ecstat column types

* Change prevten field type

* Change homeless field type

* Change benefit cap field type

* Put db enums in one folder and add a few new field changes"

* change field type for housing needs

* Change illness field type

* display checkbox answers

* cbl, chr, cap

* Change tenancy and tenancylength field types

* Change landlord and rsnvac field types

* Change unittype_gn field type

* Reasonble preference displaying on check answers

* update more field types

* Fix typo in comumn name

* Change more types

* Test fixes

* Add adr

* fix some tests

* run migration

* Fix tests

Co-authored-by: Matthew Phelan <matthew.phelan@madetech.com>
pull/80/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
5ae2f120a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/admin/case_logs.rb
  2. 252
      app/constants/db_enums.rb
  3. 2
      app/controllers/case_logs_controller.rb
  4. 93
      app/models/case_log.rb
  5. 17
      app/models/form.rb
  6. 14
      app/validations/financial_validations.rb
  7. 98
      app/validations/household_validations.rb
  8. 4
      app/validations/property_validations.rb
  9. 8
      app/validations/soft_validations.rb
  10. 12
      app/validations/tenancy_validations.rb
  11. 2
      app/views/form/_check_answers_table.html.erb
  12. 2
      app/views/form/_checkbox_question.html.erb
  13. 2
      app/views/form/check_answers.html.erb
  14. 302
      config/forms/2021_2022.json
  15. 106
      db/migrate/20211101192151_rename_fields.rb
  16. 131
      db/migrate/20211103090530_change_field_types.rb
  17. 184
      db/schema.rb
  18. 11
      docs/adr/adr-008-field-names.md
  19. 625
      docs/api/DLUHC-CORE-Data.v1.json
  20. 50
      spec/controllers/case_logs_controller_spec.rb
  21. 2
      spec/factories/case_log.rb
  22. 153
      spec/features/case_log_spec.rb
  23. 186
      spec/fixtures/complete_case_log.json
  24. 122
      spec/fixtures/forms/test_form.json
  25. 36
      spec/helpers/check_answers_helper_spec.rb
  26. 4
      spec/helpers/conditional_questions_helper_spec.rb
  27. 12
      spec/helpers/question_attribute_helper_spec.rb
  28. 6
      spec/helpers/tasklist_helper_spec.rb
  29. 162
      spec/models/case_log_spec.rb
  30. 2
      spec/models/form_spec.rb
  31. 20
      spec/requests/case_log_controller_spec.rb

2
app/admin/case_logs.rb

@ -2,7 +2,7 @@ ActiveAdmin.register CaseLog do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
permit_params do
permitted = %i[status tenant_code person_1_age person_1_gender tenant_ethnic_group tenant_nationality previous_housing_situation armed_forces person_1_economic_status household_number_of_other_members person_2_relationship person_2_age person_2_gender person_2_economic_status person_3_relationship person_3_age person_3_gender person_3_economic_status person_4_relationship person_4_age person_4_gender person_4_economic_status person_5_relationship person_5_age person_5_gender person_5_economic_status person_6_relationship person_6_age person_6_gender person_6_economic_status person_7_relationship person_7_age person_7_gender person_7_economic_status person_8_relationship person_8_age person_8_gender person_8_economic_status homelessness reason_for_leaving_last_settled_home benefit_cap_spare_room_subsidy armed_forces_active armed_forces_injured armed_forces_partner medical_conditions pregnancy accessibility_requirements condition_effects tenancy_code tenancy_start_date starter_tenancy fixed_term_tenancy tenancy_type letting_type letting_provider property_location previous_postcode property_relet property_vacancy_reason property_reference property_unit_type property_building_type property_number_of_bedrooms property_void_date property_major_repairs property_major_repairs_date property_number_of_times_relet property_wheelchair_accessible net_income net_income_frequency net_income_uc_proportion housing_benefit rent_frequency basic_rent service_charge personal_service_charge support_charge total_charge outstanding_amount time_lived_in_la time_on_la_waiting_list previous_la property_postcode reasonable_preference reasonable_preference_reason cbl_letting chr_letting cap_letting outstanding_rent_or_charges other_reason_for_leaving_last_settled_home accessibility_requirements_fully_wheelchair_accessible_housing accessibility_requirements_wheelchair_access_to_essential_rooms accessibility_requirements_level_access_housing accessibility_requirements_other_disability_requirements accessibility_requirements_no_disability_requirements accessibility_requirements_do_not_know accessibility_requirements_prefer_not_to_say condition_effects_vision condition_effects_hearing condition_effects_mobility condition_effects_dexterity condition_effects_stamina condition_effects_learning condition_effects_memory condition_effects_mental_health condition_effects_social_or_behavioral condition_effects_other condition_effects_prefer_not_to_say reasonable_preference_reason_homeless reasonable_preference_reason_unsatisfactory_housing reasonable_preference_reason_medical_grounds reasonable_preference_reason_avoid_hardship reasonable_preference_reason_do_not_know other_tenancy_type override_net_income_validation net_income_known]
permitted = %i[status tenant_code age1 sex1 tenant_ethnic_group tenant_nationality previous_housing_situation armed_forces ecstat1 hhmemb relat2 age2 sex2 ecstat2 relat3 age3 sex3 ecstat3 relat4 age4 sex4 ecstat4 relat5 age5 sex5 ecstat5 relat6 age6 sex6 ecstat6 relat7 age7 person_7_gender ecstat7 relat8 age8 sex8 ecstat8 homelessness reason_for_leaving_last_settled_home benefit_cap_spare_room_subsidy armed_forces_active armed_forces_injured armed_forces_partner medical_conditions pregnancy accessibility_requirements condition_effects tenancy_code tenancy_start_date starter_tenancy fixed_term_tenancy tenancy_type letting_type letting_provider property_location previous_postcode property_relet property_vacancy_reason property_reference property_unit_type property_building_type property_number_of_bedrooms property_void_date property_major_repairs property_major_repairs_date property_number_of_times_relet property_wheelchair_accessible net_income net_income_frequency net_income_uc_proportion housing_benefit rent_frequency basic_rent service_charge personal_service_charge support_charge total_charge outstanding_amount time_lived_in_la time_on_la_waiting_list previous_la property_postcode reasonable_preference reasonable_preference_reason cbl_letting chr_letting cap_letting outstanding_rent_or_charges other_reason_for_leaving_last_settled_home accessibility_requirements_fully_wheelchair_accessible_housing accessibility_requirements_wheelchair_access_to_essential_rooms accessibility_requirements_level_access_housing accessibility_requirements_other_disability_requirements accessibility_requirements_no_disability_requirements accessibility_requirements_do_not_know accessibility_requirements_prefer_not_to_say condition_effects_vision condition_effects_hearing condition_effects_mobility condition_effects_dexterity condition_effects_stamina condition_effects_learning condition_effects_memory condition_effects_mental_health condition_effects_social_or_behavioral condition_effects_other condition_effects_prefer_not_to_say reasonable_preference_reason_homeless reasonable_preference_reason_unsatisfactory_housing reasonable_preference_reason_medical_grounds reasonable_preference_reason_avoid_hardship reasonable_preference_reason_do_not_know other_tenancy_type override_net_income_validation net_income_known]
permitted
end

252
app/constants/db_enums.rb

@ -0,0 +1,252 @@
module DbEnums
def self.benefitcap
{
"Yes - benefit cap" => 5,
"Yes - removal of the spare room subsidy" => 4,
"Yes - both the benefit cap and the removal of the spare room subsidy" => 6,
"No" => 2,
"Do not know" => 3,
"Prefer not to say" => 100,
}
end
def self.ecstat
{
"Part-time - Less than 30 hours" => 2,
"Full-time - 30 hours or more" => 1,
"In government training into work, such as New Deal" => 3,
"Jobseeker" => 4,
"Retired" => 5,
"Not seeking work" => 6,
"Full-time student" => 7,
"Unable to work because of long term sick or disability" => 8,
"Child under 16" => 100,
"Other" => 0,
"Prefer not to say" => 10,
}
end
def self.ethnic
{
"White: English/Scottish/Welsh/Northern Irish/British" => 1,
"White: Irish" => 2,
"White: Gypsy/Irish Traveller" => 18,
"White: Other" => 3,
"Mixed: White & Black Caribbean" => 4,
"Mixed: White & Black African" => 5,
"Mixed: White & Asian" => 6,
"Mixed: Other" => 7,
"Asian or Asian British: Indian" => 8,
"Asian or Asian British: Pakistani" => 9,
"Asian or Asian British: Bangladeshi" => 10,
"Asian or Asian British: Chinese" => 15,
"Asian or Asian British: Other" => 11,
"Black: Caribbean" => 12,
"Black: African" => 13,
"Black: Other" => 14,
"Other Ethnic Group: Arab" => 16,
"Other Ethnic Group: Other" => 19,
"Prefer not to say" => 17,
}
end
def self.homeless
{
"Yes - assessed as homeless by a local authority and owed a homelessness duty. Including if threatened with homelessness within 56 days" => 11,
"Yes - other homelessness" => 7,
"No" => 1,
}
end
def self.illness
{
"Yes" => 1,
"No" => 2,
"Do not know" => 3,
"Prefer not to say" => 100,
}
end
def self.leftreg
{
"Yes" => 6,
"No - they left up to 5 years ago" => 4,
"No - they left more than 5 years ago" => 5,
"Prefer not to say" => 3,
}
end
def self.national
{
"UK national resident in UK" => 1,
"A current or former reserve in the UK Armed Forces (exc. National Service)" => 100,
"UK national returning from residence overseas" => 2,
"Czech Republic" => 3,
"Estonia" => 4,
"Hungary" => 5,
"Latvia" => 6,
"Lithuania" => 7,
"Poland" => 8,
"Slovakia" => 9,
"Bulgaria" => 14,
"Romania" => 15,
"Ireland" => 17,
"Other EU Economic Area (EEA country)" => 11,
"Any other country" => 12,
"Prefer not to say" => 13,
}
end
def self.pregnancy
{
"Yes" => 1,
"No" => 2,
"Prefer not to say" => 3,
}
end
def self.previous_tenancy
{
"Owner occupation (private) " => 26,
"Owner occupation (low cost home ownership)" => 27,
"Private sector tenancy" => 3,
"Tied housing or rented with job" => 4,
"Supported housing" => 5,
"Sheltered accomodation" => 8,
"Residential care home" => 9,
"Living with friends or family" => 28,
"Refuge" => 21,
"Hospital" => 10,
"Prison / approved probation hostel" => 29,
"Direct access hostel" => 7,
"Bed & Breakfast" => 14,
"Mobile home / caravan" => 23,
"Any other temporary accommodation" => 18,
"Home Office Asylum Support" => 24,
"Children’s home / foster care" => 13,
"Rough sleeping" => 19,
"Other" => 25,
"Fixed term Local Authority General Needs tenancy" => 30,
"Lifetime Local Authority General Needs tenancy" => 31,
"Fixed term PRP General Needs tenancy" => 32,
"Lifetime PRP General Needs tenancy" => 33,
}
end
def self.reservist
{
"Yes" => 1,
"No" => 2,
"Prefer not to say" => 3,
}
end
def self.polar
{
"No" => 0,
"Yes" => 1,
}
end
def self.polar2
{
"No" => 2,
"Yes" => 1,
}
end
def self.tenancy
{
"Fixed term – Secure" => 1,
"Fixed term – Assured Shorthold Tenancy (AST)" => 4,
"Lifetime – Secure" => 100,
"Lifetime – Assured" => 2,
"License agreement" => 5,
"Other" => 3,
}
end
def self.landlord
{
"This landlord" => 1,
"Another registered provider - includes housing association or local authority" => 2,
}
end
def self.rsnvac
{
"First let of newbuild property" => 15,
"First let of conversion/rehabilitation/acquired property" => 16,
"First let of leased property" => 17,
"Relet - tenant evicted due to arrears" => 10,
"Relet - tenant evicted due to ASB or other reason" => 11,
"Relet - tenant died (no succession)" => 5,
"Relet - tenant moved to other social housing provider" => 12,
"Relet - tenant abandoned property" => 6,
"Relet - tenant moved to private sector or other accommodation" => 8,
"Relet - to tenant who occupied same property as temporary accommodation" => 9,
"Relet – internal transfer (excluding renewals of a fixed-term tenancy)" => 13,
"Relet – renewal of fixed-term tenancy" => 14,
"Relet – tenant moved to care home" => 18,
"Relet – tenant involved in a succession downsize" => 19,
}
end
def self.unittype_gn
{
"Flat / maisonette" => 1,
"Bed-sit" => 2,
"House" => 7,
"Bungalow" => 8,
"Shared flat / maisonette" => 4,
"Shared house" => 9,
"Shared bungalow" => 10,
"Other" => 6,
}
end
def self.incfreq
{
"Weekly" => 1,
"Monthly" => 2,
"Yearly" => 3,
}
end
def self.benefits
{
"All" => 1,
"Some" => 2,
"None" => 3,
"Do not know" => 4,
}
end
def self.period
{
"Weekly for 52 weeks" => 1,
"Fortnightly" => 2,
"Four-weekly" => 3,
"Calendar monthly" => 4,
"Weekly for 50 weeks" => 5,
"Weekly for 49 weeks" => 6,
"Weekly for 48 weeks" => 7,
"Weekly for 47 weeks" => 8,
"Weekly for 46 weeks" => 9,
"Weekly for 53 weeks" => 10,
}
end
def self.latime
{
"Just moved to local authority area" => 1,
"Less than 1 year" => 2,
"1 to 2 years" => 7,
"2 to 3 years" => 8,
"3 to 4 years" => 9,
"4 to 5 years" => 10,
"5 years or more" => 5,
"Do not know" => 6,
}
end
end

2
app/controllers/case_logs_controller.rb

@ -107,7 +107,7 @@ private
if question_info["type"] == "checkbox"
question_info["answer_options"].keys.reject { |x| x.match(/divider/) }.each do |option|
result[option] = question_params.include?(option)
result[option] = question_params.include?(option) ? "Yes" : "No"
end
else
result[question_key] = question_params

93
app/models/case_log.rb

@ -37,6 +37,7 @@ end
class CaseLog < ApplicationRecord
include Discard::Model
include SoftValidations
include DbEnums
default_scope -> { kept }
scope :not_completed, -> { where.not(status: "completed") }
@ -47,6 +48,60 @@ class CaseLog < ApplicationRecord
enum status: { "not_started" => 0, "in_progress" => 1, "completed" => 2 }
enum ethnic: DbEnums.ethnic
enum national: DbEnums.national, _suffix: true
enum ecstat1: DbEnums.ecstat, _suffix: true
enum ecstat2: DbEnums.ecstat, _suffix: true
enum ecstat3: DbEnums.ecstat, _suffix: true
enum ecstat4: DbEnums.ecstat, _suffix: true
enum ecstat5: DbEnums.ecstat, _suffix: true
enum ecstat6: DbEnums.ecstat, _suffix: true
enum ecstat7: DbEnums.ecstat, _suffix: true
enum ecstat8: DbEnums.ecstat, _suffix: true
enum prevten: DbEnums.previous_tenancy, _suffix: true
enum homeless: DbEnums.homeless, _suffix: true
enum underoccupation_benefitcap: DbEnums.benefitcap, _suffix: true
enum reservist: DbEnums.reservist, _suffix: true
enum leftreg: DbEnums.leftreg, _suffix: true
enum illness: DbEnums.illness, _suffix: true
enum preg_occ: DbEnums.pregnancy, _suffix: true
enum housingneeds_a: DbEnums.polar, _suffix: true
enum housingneeds_b: DbEnums.polar, _suffix: true
enum housingneeds_c: DbEnums.polar, _suffix: true
enum housingneeds_f: DbEnums.polar, _suffix: true
enum housingneeds_g: DbEnums.polar, _suffix: true
enum housingneeds_h: DbEnums.polar, _suffix: true
enum illness_type_1: DbEnums.polar, _suffix: true
enum illness_type_2: DbEnums.polar, _suffix: true
enum illness_type_3: DbEnums.polar, _suffix: true
enum illness_type_4: DbEnums.polar, _suffix: true
enum illness_type_5: DbEnums.polar, _suffix: true
enum illness_type_6: DbEnums.polar, _suffix: true
enum illness_type_7: DbEnums.polar, _suffix: true
enum illness_type_8: DbEnums.polar, _suffix: true
enum illness_type_9: DbEnums.polar, _suffix: true
enum illness_type_10: DbEnums.polar, _suffix: true
enum startertenancy: DbEnums.polar2, _suffix: true
enum tenancy: DbEnums.tenancy, _suffix: true
enum landlord: DbEnums.landlord, _suffix: true
enum rsnvac: DbEnums.rsnvac, _suffix: true
enum unittype_gn: DbEnums.unittype_gn, _suffix: true
enum rp_homeless: DbEnums.polar, _suffix: true
enum rp_insan_unsat: DbEnums.polar, _suffix: true
enum rp_medwel: DbEnums.polar, _suffix: true
enum rp_hardship: DbEnums.polar, _suffix: true
enum rp_dontknow: DbEnums.polar, _suffix: true
enum cbl: DbEnums.polar2, _suffix: true
enum chr: DbEnums.polar2, _suffix: true
enum cap: DbEnums.polar2, _suffix: true
enum wchair: DbEnums.polar2, _suffix: true
enum incfreq: DbEnums.incfreq, _suffix: true
enum benefits: DbEnums.benefits, _suffix: true
enum period: DbEnums.period, _suffix: true
enum layear: DbEnums.latime, _suffix: true
enum lawaitlist: DbEnums.latime, _suffix: true
enum reasonpref: DbEnums.polar2, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
def self.editable_fields
@ -66,20 +121,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,33 +166,33 @@ 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
start_range = (hhmemb || 0) + 2
(start_range..8).each do |n|
dynamically_not_required << "person_#{n}_age"
dynamically_not_required << "person_#{n}_gender"
dynamically_not_required << "person_#{n}_relationship"
dynamically_not_required << "person_#{n}_economic_status"
dynamically_not_required << "age#{n}"
dynamically_not_required << "sex#{n}"
dynamically_not_required << "relat#{n}"
dynamically_not_required << "ecstat#{n}"
end
required.delete_if { |key, _value| dynamically_not_required.include?(key) }

17
app/models/form.rb

@ -90,4 +90,21 @@ class Form
pages_for_subsection(subsection).keys[current_page_idx - 1]
end
def all_questions
@all_questions ||= all_pages.map { |_page_key, page_value|
page_value["questions"]
}.reduce(:merge)
end
def get_answer_label(case_log, question_title)
question = all_questions[question_title]
if question["type"] == "checkbox"
answer = []
question["answer_options"].each { |key, value| case_log[key] == "Yes" ? answer << value : nil }
return answer.join(", ")
end
case_log[question_title]
end
end

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

98
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
@ -63,10 +63,10 @@ module HouseholdValidations
end
def validate_person_1_age(record)
return unless record.person_1_age
return unless record.age1
if !record.person_1_age.is_a?(Integer) || record.person_1_age < 16 || record.person_1_age > 120
record.errors.add "person_1_age", "Tenant age must be an integer between 16 and 120"
if !record.age1.is_a?(Integer) || record.age1 < 16 || record.age1 > 120
record.errors.add "age1", "Tenant age must be an integer between 16 and 120"
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,72 +94,72 @@ 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
def validate_person_age(record, person_num)
age = record.public_send("person_#{person_num}_age")
age = record.public_send("age#{person_num}")
return unless age
if !age.is_a?(Integer) || age < 1 || age > 120
record.errors.add "person_#{person_num}_age".to_sym, "Tenant age must be an integer between 0 and 120"
record.errors.add "age#{person_num}".to_sym, "Tenant age must be an integer between 0 and 120"
end
end
def validate_person_age_matches_economic_status(record, person_num)
age = record.public_send("person_#{person_num}_age")
economic_status = record.public_send("person_#{person_num}_economic_status")
age = record.public_send("age#{person_num}")
economic_status = record.public_send("ecstat#{person_num}")
return unless age && economic_status
if age > 70 && economic_status != "Retired"
record.errors.add "person_#{person_num}_economic_status", "Tenant #{person_num} must be retired if over 70"
record.errors.add "ecstat#{person_num}", "Tenant #{person_num} must be retired if over 70"
end
if age < 16 && economic_status != "Child under 16"
record.errors.add "person_#{person_num}_economic_status", "Tenant #{person_num} economic status must be Child under 16 if their age is under 16"
record.errors.add "ecstat#{person_num}", "Tenant #{person_num} economic status must be Child under 16 if their age is under 16"
end
end
def validate_person_age_matches_relationship(record, person_num)
age = record.public_send("person_#{person_num}_age")
relationship = record.public_send("person_#{person_num}_relationship")
age = record.public_send("age#{person_num}")
relationship = record.public_send("relat#{person_num}")
return unless age && relationship
if age < 16 && relationship != "Child - includes young adult and grown-up"
record.errors.add "person_#{person_num}_relationship", "Tenant #{person_num}'s relationship to tenant 1 must be Child if their age is under 16"
record.errors.add "relat#{person_num}", "Tenant #{person_num}'s relationship to tenant 1 must be Child if their age is under 16"
end
end
def validate_person_age_and_relationship_matches_economic_status(record, person_num)
age = record.public_send("person_#{person_num}_age")
economic_status = record.public_send("person_#{person_num}_economic_status")
relationship = record.public_send("person_#{person_num}_relationship")
age = record.public_send("age#{person_num}")
economic_status = record.public_send("ecstat#{person_num}")
relationship = record.public_send("relat#{person_num}")
return unless age && economic_status && relationship
if age >= 16 && age <= 19 && relationship == "Child - includes young adult and grown-up" && (economic_status != "Full-time student" || economic_status != "Prefer not to say")
record.errors.add "person_#{person_num}_economic_status", "If age is between 16 and 19 - tenant #{person_num} must be a full time student or prefer not to say."
record.errors.add "ecstat#{person_num}", "If age is between 16 and 19 - tenant #{person_num} must be a full time student or prefer not to say."
end
end
def validate_person_age_and_gender_match_economic_status(record, person_num)
age = record.public_send("person_#{person_num}_age")
gender = record.public_send("person_#{person_num}_gender")
economic_status = record.public_send("person_#{person_num}_economic_status")
age = record.public_send("age#{person_num}")
gender = record.public_send("sex#{person_num}")
economic_status = record.public_send("ecstat#{person_num}")
return unless age && economic_status && gender
if gender == "Male" && economic_status == "Retired" && age < 65
record.errors.add "person_#{person_num}_age", "Male tenant who is retired must be 65 or over"
record.errors.add "age#{person_num}", "Male tenant who is retired must be 65 or over"
end
if gender == "Female" && economic_status == "Retired" && age < 60
record.errors.add "person_#{person_num}_age", "Female tenant who is retired must be 60 or over"
record.errors.add "age#{person_num}", "Female tenant who is retired must be 60 or over"
end
end
def validate_partner_count(record)
# TODO: probably need to keep track of which specific field is wrong so we can highlight it in the UI
partner_count = (2..8).count { |n| record.public_send("person_#{n}_relationship") == "Partner" }
partner_count = (2..8).count { |n| record.public_send("relat#{n}") == "Partner" }
if partner_count > 1
record.errors.add :base, "Number of partners cannot be greater than 1"
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, "Property number of times relet must be between 0 and 20"
end
end
end

8
app/validations/soft_validations.rb

@ -18,12 +18,12 @@ private
if net_income_in_soft_min_range?
net_income_errors["override_net_income_validation"] = OpenStruct.new(
message: "Net income is lower than expected based on the main tenant's working situation. Are you sure this is correct?",
hint_text: "This is based on the tenant's work situation: #{person_1_economic_status}",
hint_text: "This is based on the tenant's work situation: #{ecstat1}",
)
elsif net_income_in_soft_max_range?
net_income_errors["override_net_income_validation"] = OpenStruct.new(
message: "Net income is higher than expected based on the main tenant's working situation. Are you sure this is correct?",
hint_text: "This is based on the tenant's work situation: #{person_1_economic_status}",
hint_text: "This is based on the tenant's work situation: #{ecstat1}",
)
else
update_column(:override_net_income_validation, nil)
@ -32,13 +32,13 @@ private
end
def net_income_in_soft_max_range?
return unless weekly_net_income && person_1_economic_status
return unless weekly_net_income && ecstat1
weekly_net_income.between?(applicable_income_range.soft_max, applicable_income_range.hard_max)
end
def net_income_in_soft_min_range?
return unless weekly_net_income && person_1_economic_status
return unless weekly_net_income && ecstat1
weekly_net_income.between?(applicable_income_range.soft_min, applicable_income_range.hard_min)
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

2
app/views/form/_check_answers_table.html.erb

@ -4,7 +4,7 @@
<%= question_info["check_answer_label"].to_s.present? ? question_info["check_answer_label"].to_s : question_info["header"].to_s%>
<dt>
<dd class="govuk-summary-list__value">
<%= @case_log[question_title] %>
<%= form.get_answer_label(@case_log, question_title) %>
</dd>
<dd class="govuk-summary-list__actions">
<%= create_update_answer_link(@case_log[question_title], @case_log.id, page)%>

2
app/views/form/_checkbox_question.html.erb

@ -8,7 +8,7 @@
<% else %>
<%= f.govuk_check_box question_key, key,
label: { text: val },
checked: f.object.send(key),
checked: @case_log[key] == "Yes",
**stimulus_html_attributes(question)
%>
<% end %>

2
app/views/form/check_answers.html.erb

@ -6,7 +6,7 @@
<% form.pages_for_subsection(subsection).each do |page, page_info| %>
<% page_info["questions"].each do |question_title, question_info| %>
<% if total_questions(subsection, @case_log, form).include?(question_title) %>
<%= render partial: 'form/check_answers_table', locals: { question_title: question_title, question_info: question_info, case_log: @case_log, page: page } %>
<%= render partial: 'form/check_answers_table', locals: { question_title: question_title, question_info: question_info, case_log: @case_log, page: page, form: form } %>
<%end %>
<%end %>
<% end %>

302
config/forms/2021_2022.json

@ -196,11 +196,11 @@
}
}
},
"person_1_age": {
"age1": {
"header": "",
"description": "",
"questions": {
"person_1_age": {
"age1": {
"check_answer_label": "Tenant's age",
"header": "What is the tenant's age?",
"hint_text": "",
@ -211,11 +211,11 @@
}
}
},
"person_1_gender": {
"sex1": {
"header": "",
"description": "",
"questions": {
"person_1_gender": {
"sex1": {
"check_answer_label": "Tenant's gender",
"header": "Which of these best describes the tenant's gender identity?",
"hint_text": "",
@ -233,7 +233,7 @@
"header": "",
"description": "",
"questions": {
"tenant_ethnic_group": {
"ethnic": {
"check_answer_label": "Ethnicity",
"header": "What is the tenant's ethnic group?",
"hint_text": "",
@ -266,7 +266,7 @@
"header": "",
"description": "",
"questions": {
"tenant_nationality": {
"national": {
"check_answer_label": "Nationality",
"header": "What is the tenant's nationality?",
"hint_text": "",
@ -296,7 +296,7 @@
"header": "",
"description": "",
"questions": {
"person_1_economic_status": {
"ecstat1": {
"check_answer_label": "Work",
"header": "Which of these best describes the tenant's working situation?",
"hint_text": "",
@ -321,7 +321,7 @@
"header": "",
"description": "",
"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 7",
@ -330,37 +330,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"
}
},
"person_2_relationship": {
"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": {
"check_answer_label": "Person 2's relationship to lead tenant",
"header": "What's person 2's relationship to lead tenant",
"hint_text": "",
@ -372,7 +372,7 @@
"3": "Prefer not to say"
}
},
"person_2_age": {
"age2": {
"check_answer_label": "Person 2's age",
"header": "What's person 2's age",
"hint_text": "",
@ -381,7 +381,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?",
"hint_text": "",
@ -393,7 +393,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?",
"hint_text": "",
@ -412,7 +412,7 @@
"10": "Prefer not to say"
}
},
"person_3_relationship": {
"relat3": {
"check_answer_label": "Person 3's relationship to lead tenant",
"header": "What's person 3's relationship to lead tenant",
"hint_text": "",
@ -424,7 +424,7 @@
"3": "Prefer not to say"
}
},
"person_3_age": {
"age3": {
"check_answer_label": "Person 3's age",
"header": "What's person 3's age",
"hint_text": "",
@ -433,7 +433,7 @@
"max": 150,
"step": 1
},
"person_3_gender": {
"sex3": {
"check_answer_label": "Person 3's gender",
"header": "Which of these best describes person 3's gender identity?",
"hint_text": "",
@ -445,7 +445,7 @@
"3": "Prefer not to say"
}
},
"person_3_economic_status": {
"ecstat3": {
"check_answer_label": "Person 3's Work",
"header": "Which of these best describes person 3's working situation?",
"hint_text": "",
@ -464,7 +464,7 @@
"10": "Prefer not to say"
}
},
"person_4_relationship": {
"relat4": {
"check_answer_label": "Person 4's relationship to lead tenant",
"header": "What's person 4's relationship to lead tenant",
"hint_text": "",
@ -476,7 +476,7 @@
"3": "Prefer not to say"
}
},
"person_4_age": {
"age4": {
"check_answer_label": "Person 4's age",
"header": "What's person 4's age",
"hint_text": "",
@ -485,7 +485,7 @@
"max": 150,
"step": 1
},
"person_4_gender": {
"sex4": {
"check_answer_label": "Person 4's gender",
"header": "Which of these best describes person 4's gender identity?",
"hint_text": "",
@ -497,7 +497,7 @@
"3": "Prefer not to say"
}
},
"person_4_economic_status": {
"ecstat4": {
"check_answer_label": "Person 4's Work",
"header": "Which of these best describes person 4's working situation?",
"hint_text": "",
@ -516,7 +516,7 @@
"10": "Prefer not to say"
}
},
"person_5_relationship": {
"relat5": {
"check_answer_label": "Person 5's relationship to lead tenant",
"header": "What's person 5's relationship to lead tenant",
"hint_text": "",
@ -528,7 +528,7 @@
"3": "Prefer not to say"
}
},
"person_5_age": {
"age5": {
"check_answer_label": "Person 5's age",
"header": "What's person 5's age",
"hint_text": "",
@ -537,7 +537,7 @@
"max": 150,
"step": 1
},
"person_5_gender": {
"sex5": {
"check_answer_label": "Person 5's gender",
"header": "Which of these best describes person 5's gender identity?",
"hint_text": "",
@ -549,7 +549,7 @@
"3": "Prefer not to say"
}
},
"person_5_economic_status": {
"ecstat5": {
"check_answer_label": "Person 5's Work",
"header": "Which of these best describes person 5's working situation?",
"hint_text": "",
@ -568,7 +568,7 @@
"10": "Prefer not to say"
}
},
"person_6_relationship": {
"relat6": {
"check_answer_label": "Person 6's relationship to lead tenant",
"header": "What's person 6's relationship to lead tenant",
"hint_text": "",
@ -580,7 +580,7 @@
"3": "Prefer not to say"
}
},
"person_6_age": {
"age6": {
"check_answer_label": "Person 6's age",
"header": "What's person 6's age",
"hint_text": "",
@ -589,7 +589,7 @@
"max": 150,
"step": 1
},
"person_6_gender": {
"sex6": {
"check_answer_label": "Person 6's gender",
"header": "Which of these best describes person 6's gender identity?",
"hint_text": "",
@ -601,7 +601,7 @@
"3": "Prefer not to say"
}
},
"person_6_economic_status": {
"ecstat6": {
"check_answer_label": "Person 6's Work",
"header": "Which of these best describes person 6's working situation?",
"hint_text": "",
@ -620,7 +620,7 @@
"10": "Prefer not to say"
}
},
"person_7_relationship": {
"relat7": {
"check_answer_label": "Person 7's relationship to lead tenant",
"header": "What's person 7's relationship to lead tenant",
"hint_text": "",
@ -632,7 +632,7 @@
"3": "Prefer not to say"
}
},
"person_7_age": {
"age7": {
"check_answer_label": "Person 7's age",
"header": "What's person 7's age",
"hint_text": "",
@ -641,7 +641,7 @@
"max": 150,
"step": 1
},
"person_7_gender": {
"sex7": {
"check_answer_label": "Person 7's gender",
"header": "Which of these best describes person 7's gender identity?",
"hint_text": "",
@ -653,7 +653,7 @@
"3": "Prefer not to say"
}
},
"person_7_economic_status": {
"ecstat7": {
"check_answer_label": "Person 7's Work",
"header": "Which of these best describes person 7's working situation?",
"hint_text": "",
@ -672,7 +672,7 @@
"10": "Prefer not to say"
}
},
"person_8_relationship": {
"relat8": {
"check_answer_label": "Person 8's relationship to lead tenant",
"header": "What's person 8's relationship to lead tenant",
"hint_text": "",
@ -684,7 +684,7 @@
"3": "Prefer not to say"
}
},
"person_8_age": {
"age8": {
"check_answer_label": "Person 8's age",
"header": "What's person 8's age",
"hint_text": "",
@ -693,7 +693,7 @@
"max": 150,
"step": 1
},
"person_8_gender": {
"sex8": {
"check_answer_label": "Person 8's gender",
"header": "Which of these best describes person 8's gender identity?",
"hint_text": "",
@ -705,7 +705,7 @@
"3": "Prefer not to say"
}
},
"person_8_economic_status": {
"ecstat8": {
"check_answer_label": "Person 8's Work",
"header": "Which of these best describes person 8's working situation?",
"hint_text": "",
@ -735,7 +735,7 @@
"header": "",
"description": "",
"questions": {
"previous_housing_situation": {
"prevten": {
"header": "What was the tenant’s housing situation immediately before this letting?",
"hint_text": "",
"type": "radio",
@ -771,7 +771,7 @@
"header": "",
"description": "",
"questions": {
"homelessness": {
"homeless": {
"header": "Did the tenant experience homelessness immediately before this letting?",
"hint_text": "",
"type": "radio",
@ -836,7 +836,7 @@
"hint_text": "",
"type": "text"
},
"benefit_cap_spare_room_subsidy": {
"underoccupation_benefitcap": {
"header": "Was the reason for leaving because of the benefit cap or removal of the spare room subsidy?",
"hint_text": "",
"type": "radio",
@ -872,11 +872,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?",
"hint_text": "",
"type": "radio",
@ -888,7 +888,7 @@
"3": "Prefer not to say"
}
},
"armed_forces_injured": {
"reservist": {
"header": "Were they seriously injured or ill as a result of their service?",
"hint_text": "",
"type": "radio",
@ -917,7 +917,7 @@
"header": "",
"description": "",
"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>",
"hint_text": "",
"type": "radio",
@ -935,7 +935,7 @@
"header": "",
"description": "",
"questions": {
"pregnancy": {
"preg_occ": {
"header": "Is anyone in the household pregnant?",
"hint_text": "",
"type": "radio",
@ -958,13 +958,13 @@
"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",
"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"
}
@ -981,16 +981,16 @@
"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",
"condition_effects_mobility": "Mobility - such as walking short distances or climbing stairs",
"condition_effects_dexterity": "Dexterity - such as lifting and carrying objects or using a keyboard",
"condition_effects_stamina": "Stamina or breathing or fatigue",
"condition_effects_learning": "Learning or understanding or concentrating",
"condition_effects_memory": "Memory",
"condition_effects_mental_health": "Mental health - such as depression, anxiety, schizophrenia or bipolar",
"condition_effects_social_or_behavioral": "Socially or behaviourally - such as those associated with autism spectral disorder (ASD) including Aspergers’ or attention deficit hyperactivity disorder (ADHD))",
"condition_effects_other": "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"
}
@ -1023,7 +1023,7 @@
"header": "",
"description": "",
"questions": {
"tenancy_start_date": {
"startdate": {
"check_answer_label": "When is the tenancy start date?",
"header": "What is the tenancy start date?",
"hint_text": "For example, 27 3 2007",
@ -1035,7 +1035,7 @@
"header": "",
"description": "",
"questions": {
"starter_tenancy": {
"startertenancy": {
"check_answer_label": "Is this a starter or introductory tenancy?",
"header": "Is this a starter tenancy?",
"hint_text": "",
@ -1051,7 +1051,7 @@
"header": "",
"description": "",
"questions": {
"fixed_term_tenancy": {
"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",
@ -1066,7 +1066,7 @@
"header": "",
"description": "",
"questions": {
"tenancy_type": {
"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": "",
@ -1083,7 +1083,7 @@
"other_tenancy_type": ["Other"]
}
},
"other_tenancy_type": {
"tenancyother": {
"header": "Please state the tenancy type",
"hint_text": "",
"type": "text"
@ -1094,7 +1094,7 @@
"header": "",
"description": "",
"questions": {
"letting_type": {
"lettype": {
"check_answer_label": "Type of letting",
"header": "Which type of letting is this?",
"hint_text": "",
@ -1114,7 +1114,7 @@
"header": "",
"description": "",
"questions": {
"letting_provider": {
"landlord": {
"check_answer_label": "Provider",
"header": "Who is the letting provider?",
"hint_text": "",
@ -1490,7 +1490,7 @@
"header": "",
"description": "",
"questions": {
"property_vacancy_reason": {
"rsnvac": {
"check_answer_label": "What is the reason for the property vacancy?",
"header": "What is the reason for the property vacancy?",
"hint_text": "",
@ -1530,7 +1530,7 @@
"header": "",
"description": "",
"questions": {
"property_unit_type": {
"unittype_gn": {
"check_answer_label": "Which type of unit is the property?",
"header": "Which type of unit is the property?",
"hint_text": "",
@ -1552,7 +1552,7 @@
"header": "",
"description": "",
"questions": {
"property_number_of_bedrooms": {
"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",
@ -1592,7 +1592,7 @@
"header": "",
"description": "",
"questions": {
"property_number_of_times_relet": {
"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' ",
@ -1607,7 +1607,7 @@
"header": "",
"description": "",
"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?",
"hint_text": "",
@ -1644,11 +1644,11 @@
"2": "Tenant prefers not to say"
},
"conditional_for": {
"net_income": ["Yes"],
"net_income_frequency": ["Yes"]
"earnings": ["Yes"],
"incfreq": ["Yes"]
}
},
"net_income": {
"earnings": {
"check_answer_label": "Income",
"header": "What is the tenant’s /and partner’s combined income after tax?",
"hint_text": "",
@ -1656,7 +1656,7 @@
"min": 0,
"step": "1"
},
"net_income_frequency": {
"incfreq": {
"check_answer_label": "Income Frequency",
"header": "How often do they receive this income?",
"hint_text": "",
@ -1682,7 +1682,7 @@
"header": "",
"description": "",
"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?",
"hint_text": "",
@ -1701,7 +1701,7 @@
"description": "",
"questions": {
"housing_benefit": {
"check_answer_label": "Universal Credit & Housing Benefit\t",
"check_answer_label": "Universal Credit & Housing Benefit",
"header": "Is the tenant likely to be in receipt of any of these housing-related benefits?",
"hint_text": "",
"type": "radio",
@ -1726,7 +1726,7 @@
"header": "",
"description": "",
"questions": {
"rent_frequency": {
"period": {
"check_answer_label": "Rent Period",
"header": "Which period are rent and other charges due?",
"hint_text": "",
@ -1744,47 +1744,67 @@
"9": "Weekly for 53 weeks"
}
},
"basic_rent": {
"brent": {
"check_answer_label": "Basic Rent",
"header": "What is the basic rent?",
"hint_text": "Eligible for housing benefit or Universal Credit",
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": ["basic_rent", "service_charge", "personal_service_charge", "support_charge"],
"result-field": "total_charge"
},
"service_charge": {
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge"
},
"scharge": {
"check_answer_label": "Service Charge",
"header": "What is the service charge?",
"hint_text": "Eligible for housing benefit or Universal Credit",
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": ["basic_rent", "service_charge", "personal_service_charge", "support_charge"],
"result-field": "total_charge"
},
"personal_service_charge": {
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge"
},
"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.",
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": ["basic_rent", "service_charge", "personal_service_charge", "support_charge"],
"result-field": "total_charge"
},
"support_charge": {
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge"
},
"supcharg": {
"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",
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": ["basic_rent", "service_charge", "personal_service_charge", "support_charge"],
"result-field": "total_charge"
},
"total_charge": {
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge"
},
"tcharge": {
"check_answer_label": "Total Charge",
"header": "Total charge?",
"hint_text": "This is the total of rent and all charges",
@ -1830,7 +1850,7 @@
"header": "",
"description": "",
"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?",
"hint_text": "",
@ -1852,7 +1872,7 @@
"header": "",
"description": "",
"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?",
"hint_text": "",
@ -2213,7 +2233,7 @@
"header": "",
"description": "",
"questions": {
"reasonable_preference": {
"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": "",
@ -2232,12 +2252,12 @@
"hint_text": "Select all that apply",
"type": "checkbox",
"answer_options": {
"reasonable_preference_reason_homeless": "Homeless or about to lose their home (within 56 days)",
"reasonable_preference_reason_unsatisfactory_housing": "Living in insanitary or overcrowded or unsatisfactory housing",
"reasonable_preference_reason_medical_grounds": "A need to move on medical and welfare grounds (including a disability)",
"reasonable_preference_reason_avoid_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,
"reasonable_preference_reason_do_not_know": "Do not know"
"rp_dontknow": "Do not know"
}
}
}
@ -2246,9 +2266,9 @@
"header": "",
"description": "",
"questions": {
"cbl_letting": {
"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": {
@ -2256,9 +2276,9 @@
"1": "No"
}
},
"chr_letting": {
"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": {
@ -2266,9 +2286,9 @@
"1": "No"
}
},
"cap_letting": {
"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": {

106
db/migrate/20211101192151_rename_fields.rb

@ -0,0 +1,106 @@
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, :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_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_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_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, :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, :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, :supcharg
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, :cbl_letting, :cbl
rename_column :case_logs, :chr_letting, :chr
rename_column :case_logs, :cap_letting, :cap
end
end

131
db/migrate/20211103090530_change_field_types.rb

@ -0,0 +1,131 @@
class ChangeFieldTypes < ActiveRecord::Migration[6.1]
def up
change_table :case_logs, bulk: true do |t|
t.change :ethnic, "integer USING ethnic::integer"
t.change :national, "integer USING national::integer"
t.change :ecstat1, "integer USING ecstat1::integer"
t.change :ecstat2, "integer USING ecstat2::integer"
t.change :ecstat3, "integer USING ecstat3::integer"
t.change :ecstat4, "integer USING ecstat4::integer"
t.change :ecstat5, "integer USING ecstat5::integer"
t.change :ecstat6, "integer USING ecstat6::integer"
t.change :ecstat7, "integer USING ecstat7::integer"
t.change :ecstat8, "integer USING ecstat8::integer"
t.change :prevten, "integer USING prevten::integer"
t.change :homeless, "integer USING homeless::integer"
t.change :underoccupation_benefitcap, "integer USING underoccupation_benefitcap::integer"
t.change :reservist, "integer USING reservist::integer"
t.change :leftreg, "integer USING leftreg::integer"
t.change :illness, "integer USING illness::integer"
t.change :preg_occ, "integer USING preg_occ::integer"
t.change :housingneeds_a, "integer USING housingneeds_a::integer"
t.change :housingneeds_b, "integer USING housingneeds_b::integer"
t.change :housingneeds_c, "integer USING housingneeds_c::integer"
t.change :housingneeds_f, "integer USING housingneeds_f::integer"
t.change :housingneeds_g, "integer USING housingneeds_g::integer"
t.change :housingneeds_h, "integer USING housingneeds_h::integer"
t.change :illness_type_1, "integer USING illness_type_1::integer"
t.change :illness_type_2, "integer USING illness_type_2::integer"
t.change :illness_type_3, "integer USING illness_type_3::integer"
t.change :illness_type_4, "integer USING illness_type_4::integer"
t.change :illness_type_5, "integer USING illness_type_5::integer"
t.change :illness_type_6, "integer USING illness_type_6::integer"
t.change :illness_type_7, "integer USING illness_type_7::integer"
t.change :illness_type_8, "integer USING illness_type_8::integer"
t.change :illness_type_9, "integer USING illness_type_9::integer"
t.change :illness_type_10, "integer USING illness_type_10::integer"
t.change :rp_homeless, "integer USING rp_homeless::integer"
t.change :rp_insan_unsat, "integer USING rp_insan_unsat::integer"
t.change :rp_medwel, "integer USING rp_medwel::integer"
t.change :rp_hardship, "integer USING rp_hardship::integer"
t.change :rp_dontknow, "integer USING rp_dontknow::integer"
t.change :cbl, "integer USING cbl::integer"
t.change :chr, "integer USING chr::integer"
t.change :cap, "integer USING cap::integer"
t.change :startertenancy, "integer USING startertenancy::integer"
t.change :tenancylength, "integer USING tenancylength::integer"
t.change :tenancy, "integer USING tenancy::integer"
t.change :landlord, "integer USING landlord::integer"
t.change :rsnvac, "integer USING rsnvac::integer"
t.change :unittype_gn, "integer USING unittype_gn::integer"
t.change :beds, "integer USING beds::integer"
t.change :wchair, "integer USING wchair::integer"
t.change :incfreq, "integer USING incfreq::integer"
t.change :benefits, "integer USING benefits::integer"
t.change :period, "integer USING period::integer"
t.change :brent, "integer USING brent::integer"
t.change :scharge, "integer USING scharge::integer"
t.change :pscharge, "integer USING pscharge::integer"
t.change :supcharg, "integer USING supcharg::integer"
t.change :tcharge, "integer USING tcharge::integer"
t.change :layear, "integer USING layear::integer"
t.change :lawaitlist, "integer USING lawaitlist::integer"
t.change :reasonpref, "integer USING reasonpref::integer"
end
end
def down
change_table :case_logs, bulk: true do |t|
t.change :ethnic, :string
t.change :national, :string
t.change :ecstat1, :string
t.change :ecstat2, :string
t.change :ecstat3, :string
t.change :ecstat4, :string
t.change :ecstat5, :string
t.change :ecstat6, :string
t.change :ecstat7, :string
t.change :ecstat8, :string
t.change :prevten, :string
t.change :homeless, :string
t.change :underoccupation_benefitcap, :string
t.change :reservist, :string
t.change :leftreg, :string
t.change :illness, :string
t.change :preg_occ, :string
t.change :housingneeds_a, "boolean USING housingneeds_a::boolean"
t.change :housingneeds_b, "boolean USING housingneeds_b::boolean"
t.change :housingneeds_c, "boolean USING housingneeds_c::boolean"
t.change :housingneeds_f, "boolean USING housingneeds_f::boolean"
t.change :housingneeds_g, "boolean USING housingneeds_g::boolean"
t.change :housingneeds_h, "boolean USING housingneeds_h::boolean"
t.change :illness_type_1, "boolean USING illness_type_1::boolean"
t.change :illness_type_2, "boolean USING illness_type_2::boolean"
t.change :illness_type_3, "boolean USING illness_type_3::boolean"
t.change :illness_type_4, "boolean USING illness_type_4::boolean"
t.change :illness_type_5, "boolean USING illness_type_5::boolean"
t.change :illness_type_6, "boolean USING illness_type_6::boolean"
t.change :illness_type_7, "boolean USING illness_type_7::boolean"
t.change :illness_type_8, "boolean USING illness_type_8::boolean"
t.change :illness_type_9, "boolean USING illness_type_9::boolean"
t.change :illness_type_10, "boolean USING illness_type_10::boolean"
t.change :rp_homeless, :boolean
t.change :rp_insan_unsat, :boolean
t.change :rp_medwel, :boolean
t.change :rp_hardship, :boolean
t.change :rp_dontknow, :boolean
t.change :cbl_letting, :string
t.change :chr_letting, :string
t.change :cap_letting, :string
t.change :startertenancy, :string
t.change :tenancylength, :string
t.change :tenancy, :string
t.change :landlord, :string
t.change :rsnvac, :string
t.change :unittype_gn, :string
t.change :beds, :string
t.change :wchair, :string
t.change :incfreq, :string
t.change :benefits, :string
t.change :period, :string
t.change :brent, :string
t.change :scharge, :string
t.change :pscharge, :string
t.change :supcharg, :string
t.change :tcharge, :string
t.change :layear, :string
t.change :lawaitlist, :string
t.change :reasonpref, :string
end
end
end

184
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_11_02_100820) do
ActiveRecord::Schema.define(version: 2021_11_03_090530) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -20,119 +20,121 @@ ActiveRecord::Schema.define(version: 2021_11_02_100820) 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.integer "ethnic"
t.integer "national"
t.integer "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.integer "ecstat1"
t.integer "hhmemb"
t.string "relat2"
t.integer "age2"
t.string "sex2"
t.integer "ecstat2"
t.string "relat3"
t.integer "age3"
t.string "sex3"
t.integer "ecstat3"
t.string "relat4"
t.integer "age4"
t.string "sex4"
t.integer "ecstat4"
t.string "relat5"
t.integer "age5"
t.string "sex5"
t.integer "ecstat5"
t.string "relat6"
t.integer "age6"
t.string "sex6"
t.integer "ecstat6"
t.string "relat7"
t.integer "age7"
t.string "sex7"
t.integer "ecstat7"
t.string "relat8"
t.integer "age8"
t.string "sex8"
t.integer "ecstat8"
t.integer "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.integer "underoccupation_benefitcap"
t.integer "leftreg"
t.integer "reservist"
t.string "armed_forces_partner"
t.string "medical_conditions"
t.string "pregnancy"
t.integer "illness"
t.integer "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.integer "startertenancy"
t.integer "tenancylength"
t.integer "tenancy"
t.string "lettype"
t.integer "landlord"
t.string "property_location"
t.string "previous_postcode"
t.string "property_relet"
t.string "property_vacancy_reason"
t.integer "rsnvac"
t.string "property_reference"
t.string "property_unit_type"
t.integer "unittype_gn"
t.string "property_building_type"
t.string "property_number_of_bedrooms"
t.integer "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.integer "wchair"
t.integer "earnings"
t.integer "incfreq"
t.integer "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.integer "period"
t.integer "brent"
t.integer "scharge"
t.integer "pscharge"
t.integer "supcharg"
t.integer "tcharge"
t.string "outstanding_amount"
t.string "time_lived_in_la"
t.string "time_on_la_waiting_list"
t.integer "layear"
t.integer "lawaitlist"
t.string "previous_la"
t.string "property_postcode"
t.string "reasonable_preference"
t.integer "reasonpref"
t.string "reasonable_preference_reason"
t.string "cbl_letting"
t.string "chr_letting"
t.string "cap_letting"
t.integer "cbl"
t.integer "chr"
t.integer "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.integer "housingneeds_a"
t.integer "housingneeds_b"
t.integer "housingneeds_c"
t.integer "housingneeds_f"
t.integer "housingneeds_g"
t.integer "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.integer "illness_type_1"
t.integer "illness_type_2"
t.integer "illness_type_3"
t.integer "illness_type_4"
t.integer "illness_type_8"
t.integer "illness_type_5"
t.integer "illness_type_6"
t.integer "illness_type_7"
t.integer "illness_type_9"
t.integer "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.integer "rp_homeless"
t.integer "rp_insan_unsat"
t.integer "rp_medwel"
t.integer "rp_hardship"
t.integer "rp_dontknow"
t.datetime "discarded_at"
t.string "other_tenancy_type"
t.string "tenancyother"
t.boolean "override_net_income_validation"
t.string "net_income_known"
t.string "gdpr_acceptance"
t.string "gdpr_declined"
t.string "property_owner_organisation"
@ -144,8 +146,6 @@ ActiveRecord::Schema.define(version: 2021_11_02_100820) do
t.string "needs_type"
t.string "sale_completion_date"
t.string "purchaser_code"
t.boolean "override_net_income_validation"
t.string "net_income_known"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
end

11
docs/adr/adr-008-field-names.md

@ -0,0 +1,11 @@
### ADR - 008: Field Names
We are changing the schema to reflect the way the data is stored in CORE.
This is due to the SPSS queries that are being performed by ADD and the complexity that would come with changing them.
The field names are saved lowercase as opposed to the uppercase versions we see in CORE.
This is due to Ruby expecting the uppercase parameters to be constants and database fields are expected to be lower case.
These fields could be mapped to their uppercase versions during the replication if needed.
A lot of the values are now also being stored as enums.
This gives as some validation by default as the values not defined in the enums will fail to save.

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

File diff suppressed because it is too large Load Diff

50
spec/controllers/case_logs_controller_spec.rb

@ -49,15 +49,15 @@ 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],
%w[ housingneeds_a
housingneeds_b
housingneeds_c],
page: "accessibility_requirements" }
end
let(:new_case_log_form_params) do
{
accessibility_requirements: %w[accessibility_requirements_level_access_housing],
accessibility_requirements: %w[housingneeds_c],
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("Yes")
expect(case_log.housingneeds_b).to eq("Yes")
expect(case_log.housingneeds_c).to eq("Yes")
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("No")
expect(case_log.housingneeds_b).to eq("No")
expect(case_log.housingneeds_c).to eq("Yes")
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("Yes")
expect(case_log.housingneeds_b).to eq("Yes")
expect(case_log.housingneeds_c).to eq("Yes")
expect(case_log.tenant_code).to eq(tenant_code)
end
end
@ -130,14 +130,14 @@ RSpec.describe CaseLogsController, type: :controller do
let(:case_log_form_conditional_question_yes_params) do
{
pregnancy: "Yes",
preg_occ: "Yes",
page: "conditional_question",
}
end
let(:case_log_form_conditional_question_no_params) do
{
pregnancy: "No",
preg_occ: "No",
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 { "17" }
end
trait :completed do
status { 2 }

153
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: "Yes",
housingneeds_c: "Yes"
)
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-supcharg-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: "17")
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,32 +367,32 @@ 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
describe "Soft Validation" do
context "given a weekly net income that is above the expected amount for the given economic status but below the hard max" do
let!(:case_log) { FactoryBot.create(:case_log, :in_progress, person_1_economic_status: "Full-time - 30 hours or more") }
let!(:case_log) { FactoryBot.create(:case_log, :in_progress, ecstat1: "Full-time - 30 hours or more") }
let(:income_over_soft_limit) { 750 }
let(:income_under_soft_limit) { 700 }
it "prompts the user to confirm the value is correct" do
visit("/case_logs/#{case_log.id}/net_income")
fill_in("case-log-net-income-field", with: income_over_soft_limit)
choose("case-log-net-income-frequency-weekly-field", allow_label_click: true)
fill_in("case-log-earnings-field", with: income_over_soft_limit)
choose("case-log-incfreq-weekly-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_content("Are you sure this is correct?")
check("case-log-override-net-income-validation-override-net-income-validation-field", allow_label_click: true)
@ -401,10 +402,10 @@ RSpec.describe "Test Features" do
it "does not require confirming the value if the value is amended" do
visit("/case_logs/#{case_log.id}/net_income")
fill_in("case-log-net-income-field", with: income_over_soft_limit)
choose("case-log-net-income-frequency-weekly-field", allow_label_click: true)
fill_in("case-log-earnings-field", with: income_over_soft_limit)
choose("case-log-incfreq-weekly-field", allow_label_click: true)
click_button("Save and continue")
fill_in("case-log-net-income-field", with: income_under_soft_limit)
fill_in("case-log-earnings-field", with: income_under_soft_limit)
click_button("Save and continue")
expect(page).to have_current_path("/case_logs/#{case_log.id}/net_income_uc_proportion")
case_log.reload
@ -413,10 +414,10 @@ RSpec.describe "Test Features" do
it "clears the confirmation question if the amount was amended and the page is returned to using the back button", js: true do
visit("/case_logs/#{case_log.id}/net_income")
fill_in("case-log-net-income-field", with: income_over_soft_limit)
choose("case-log-net-income-frequency-weekly-field", allow_label_click: true)
fill_in("case-log-earnings-field", with: income_over_soft_limit)
choose("case-log-incfreq-weekly-field", allow_label_click: true)
click_button("Save and continue")
fill_in("case-log-net-income-field", with: income_under_soft_limit)
fill_in("case-log-earnings-field", with: income_under_soft_limit)
click_button("Save and continue")
click_link(text: "Back")
expect(page).not_to have_content("Are you sure this is correct?")
@ -424,8 +425,8 @@ RSpec.describe "Test Features" do
it "does not clear the confirmation question if the page is returned to using the back button and the amount is still over the soft limit", js: true do
visit("/case_logs/#{case_log.id}/net_income")
fill_in("case-log-net-income-field", with: income_over_soft_limit)
choose("case-log-net-income-frequency-weekly-field", allow_label_click: true)
fill_in("case-log-earnings-field", with: income_over_soft_limit)
choose("case-log-incfreq-weekly-field", allow_label_click: true)
click_button("Save and continue")
check("case-log-override-net-income-validation-override-net-income-validation-field", allow_label_click: true)
click_button("Save and continue")
@ -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

186
spec/fixtures/complete_case_log.json vendored

@ -1,120 +1,120 @@
{
"case_log":
{
"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",
"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",
"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",
"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",
"benefit_cap_spare_room_subsidy": "No",
"armed_forces_active": "No",
"armed_forces_injured": "No",
"underoccupation_benefitcap": "No",
"leftreg": "No - they left up to 5 years ago",
"reservist": "No",
"armed_forces_partner": "No",
"medical_conditions": "Yes",
"pregnancy": "No",
"illness": "Yes",
"preg_occ": "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",
"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",
"property_vacancy_reason": "Relet - tenant abandoned property",
"rsnvac": "Relet - tenant abandoned property",
"property_reference": "P9876",
"property_unit_type": "House",
"unittype_gn": "House",
"property_building_type": "dummy",
"property_number_of_bedrooms": 3,
"beds": 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,
"offered": 2,
"wchair": "Yes",
"net_income_known": "Yes",
"net_income": 0,
"net_income_frequency": null,
"net_income_uc_proportion": "Some",
"earnings": 0,
"incfreq": null,
"benefits": "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,
"period": "Fortnightly",
"brent": 200,
"scharge": 50,
"pscharge": 40,
"supcharg": 35,
"tcharge": 325,
"outstanding_amount": "Yes",
"time_lived_in_la": "1 to 2 years",
"time_on_la_waiting_list": "Less than 1 year",
"layear": "1 to 2 years",
"lawaitlist": "Less than 1 year",
"previous_la": "Ashford",
"property_postcode": "SE2 6RT",
"reasonable_preference": "Yes",
"reasonpref": "Yes",
"reasonable_preference_reason": "dummy",
"cbl_letting": true,
"chr_letting": false,
"cap_letting": false,
"cbl": "Yes",
"chr": "Yes",
"cap": "No",
"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,
"other_tenancy_type": "",
"housingneeds_a": "Yes",
"housingneeds_b": "No",
"housingneeds_c": "No",
"housingneeds_f": "No",
"housingneeds_g": "No",
"housingneeds_h": "No",
"accessibility_requirements_prefer_not_to_say": "No",
"illness_type_1": "No",
"illness_type_2": "Yes",
"illness_type_3": "No",
"illness_type_4": "No",
"illness_type_8": "No",
"illness_type_5": "No",
"illness_type_6": "No",
"illness_type_7": "No",
"illness_type_9": "No",
"illness_type_10": "No",
"condition_effects_prefer_not_to_say": "Yes",
"rp_homeless": "Yes",
"rp_insan_unsat": "No",
"rp_medwel": "No",
"rp_hardship": "No",
"rp_dontknow": "No",
"discarded_at": "05/05/2020",
"override_net_income_validation": "",
"gdpr_acceptance": "",
"gdpr_declined": "",
"property_owner_organisation": "",

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",
"supcharg"
],
"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",
"supcharg"
],
"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",
"supcharg"
],
"result-field": "total_charge"
"result-field": "tcharge"
},
"support_charge": {
"supcharg": {
"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",
"supcharg"
],
"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 supcharg],
"result-field" => "tcharge",
"conditional_for" => {
"next_question": ">1",
},

6
spec/helpers/tasklist_helper_spec.rb

@ -30,7 +30,11 @@ 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" }
case_log["earnings"] = "value"
case_log["incfreq"] = "Weekly"
case_log["benefits"] = "All"
case_log["housing_benefit"] = "Do not know"
status = get_subsection_status("income_and_benefits", case_log, income_and_benefits_questions)
expect(status).to eq(:completed)
end

162
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 - other homelessness",
reasonpref: "No",
rp_homeless: "Yes",
)
}.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,68 +239,68 @@ 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
context "household_member_validations" do
it "validate that persons aged under 16 must have relationship Child" do
expect { CaseLog.create!(person_2_age: 14, person_2_relationship: "Partner") }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(age2: 14, relat2: "Partner") }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validate that persons aged over 70 must be retired" do
expect { CaseLog.create!(person_2_age: 71, person_2_economic_status: "Full-time - 30 hours or more") }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(age2: 71, ecstat2: "Full-time - 30 hours or more") }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validate that a male, retired persons must be over 65" do
expect { CaseLog.create!(person_2_age: 64, person_2_gender: "Male", person_2_economic_status: "Retired") }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(age2: 64, sex2: "Male", ecstat2: "Retired") }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validate that a female, retired persons must be over 60" do
expect { CaseLog.create!(person_2_age: 59, person_2_gender: "Female", person_2_economic_status: "Retired") }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(age2: 59, sex2: "Female", ecstat2: "Retired") }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validate that persons aged under 16 must be a child (economically speaking)" do
expect { CaseLog.create!(person_2_age: 15, person_2_economic_status: "Full-time - 30 hours or more") }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(age2: 15, ecstat2: "Full-time - 30 hours or more") }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validate that persons aged between 16 and 19 that are a child must be a full time student or economic status refused" do
expect { CaseLog.create!(person_2_age: 17, person_2_relationship: "Child - includes young adult and grown-up", person_2_economic_status: "Full-time - 30 hours or more") }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(age2: 17, relat2: "Child - includes young adult and grown-up", ecstat2: "Full-time - 30 hours or more") }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validate that persons aged under 16 must be a child relationship" do
expect { CaseLog.create!(person_2_age: 15, person_2_relationship: "Partner") }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(age2: 15, relat2: "Partner") }.to raise_error(ActiveRecord::RecordInvalid)
end
it "validate that no more than 1 partner relationship exists" do
expect { CaseLog.create!(person_2_relationship: "Partner", person_3_relationship: "Partner") }.to raise_error(ActiveRecord::RecordInvalid)
expect { CaseLog.create!(relat2: "Partner", relat3: "Partner") }.to raise_error(ActiveRecord::RecordInvalid)
end
end
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 term – Secure",
tenancyother: "the other reason provided")
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy_type: "Fixed",
other_tenancy_type: nil)
CaseLog.create!(tenancy: "Fixed term – Secure",
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