diff --git a/app/constants/db_enums.rb b/app/constants/db_enums.rb index e4e6a9a98..9a87608b1 100644 --- a/app/constants/db_enums.rb +++ b/app/constants/db_enums.rb @@ -141,7 +141,7 @@ module DbEnums } end - def self.housingneeds + def self.polar { "No" => 0, "Yes" => 1, diff --git a/app/models/case_log.rb b/app/models/case_log.rb index e4ec3f8a0..b62f90a0b 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -65,12 +65,22 @@ class CaseLog < ApplicationRecord enum leftreg: DbEnums.leftreg, _suffix: true enum illness: DbEnums.illness, _suffix: true enum preg_occ: DbEnums.pregnancy, _suffix: true - enum housingneeds_a: DbEnums.housingneeds, _suffix: true - enum housingneeds_b: DbEnums.housingneeds, _suffix: true - enum housingneeds_c: DbEnums.housingneeds, _suffix: true - enum housingneeds_f: DbEnums.housingneeds, _suffix: true - enum housingneeds_g: DbEnums.housingneeds, _suffix: true - enum housingneeds_h: DbEnums.housingneeds, _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 AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze diff --git a/app/views/form/_checkbox_question.html.erb b/app/views/form/_checkbox_question.html.erb index 1d9c548e8..edb6ac74c 100644 --- a/app/views/form/_checkbox_question.html.erb +++ b/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 %> diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index f1c7ae443..6881a3285 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -64,25 +64,25 @@ "hint_text": "", "type": "radio", "answer_options": { - "1": "White: English/Scottish/Welsh/Northern Irish/British", - "2": "White: Irish", - "3": "White: Gypsy/Irish Traveller", - "4": "White: Other", - "5": "Mixed: White & Black Caribbean", - "6": "Mixed: White & Black African", - "7": "Mixed: White & Asian", - "8": "Mixed: Other", - "9": "Asian or Asian British: Indian", - "10": "Asian or Asian British: Pakistani", - "11": "Asian or Asian British: Bangladeshi", - "12": "Asian or Asian British: Chinese", - "13": "Asian or Asian British: Other", - "14": "Black: Caribbean", - "15": "Black: African", - "16": "Black: Other", - "17": "Other Ethnic Group: Arab", - "18": "Other Ethnic Group: Other", - "19": "Prefer not to say" + "0": "White: English/Scottish/Welsh/Northern Irish/British", + "1": "White: Irish", + "2": "White: Gypsy/Irish Traveller", + "3": "White: Other", + "4": "Mixed: White & Black Caribbean", + "5": "Mixed: White & Black African", + "6": "Mixed: White & Asian", + "7": "Mixed: Other", + "8": "Asian or Asian British: Indian", + "9": "Asian or Asian British: Pakistani", + "10": "Asian or Asian British: Bangladeshi", + "11": "Asian or Asian British: Chinese", + "12": "Asian or Asian British: Other", + "13": "Black: Caribbean", + "14": "Black: African", + "15": "Black: Other", + "16": "Other Ethnic Group: Arab", + "17": "Other Ethnic Group: Other", + "18": "Prefer not to say" } } } @@ -97,22 +97,22 @@ "hint_text": "", "type": "radio", "answer_options": { - "1": "UK national resident in UK", - "2": "A current or former reserve in the UK Armed Forces (exc. National Service)", - "3": "UK national returning from residence overseas", - "4": "Czech Republic", - "5": "Estonia", - "6": "Hungary", - "7": "Latvia", - "8": "Lithuania", - "9": "Poland", - "10": "Slovakia", - "11": "Bulgaria", - "12": "Romania", - "13": "Ireland", - "14": "Other EU Economic Area (EEA country)", - "15": "Any other country", - "16": "Prefer not to say" + "0": "UK national resident in UK", + "1": "A current or former reserve in the UK Armed Forces (exc. National Service)", + "2": "UK national returning from residence overseas", + "3": "Czech Republic", + "4": "Estonia", + "5": "Hungary", + "6": "Latvia", + "7": "Lithuania", + "8": "Poland", + "9": "Slovakia", + "10": "Bulgaria", + "11": "Romania", + "12": "Ireland", + "13": "Other EU Economic Area (EEA country)", + "14": "Any other country", + "15": "Prefer not to say" } } } diff --git a/db/migrate/20211103090530_change_field_types.rb b/db/migrate/20211103090530_change_field_types.rb index 8fce4b780..9cd283de9 100644 --- a/db/migrate/20211103090530_change_field_types.rb +++ b/db/migrate/20211103090530_change_field_types.rb @@ -24,6 +24,16 @@ class ChangeFieldTypes < ActiveRecord::Migration[6.1] 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" end end @@ -46,13 +56,22 @@ class ChangeFieldTypes < ActiveRecord::Migration[6.1] t.change :leftreg, :string t.change :illness, :string t.change :preg_occ, :string - t.change :housingneeds_a, :boolean - t.change :housingneeds_b, :boolean - t.change :housingneeds_c, :boolean - t.change :housingneeds_f, :boolean - t.change :housingneeds_g, :boolean - t.change :housingneeds_h, :boolean - + 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" end end end diff --git a/db/schema.rb b/db/schema.rb index a1469d57c..b944ab022 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -115,16 +115,16 @@ ActiveRecord::Schema.define(version: 2021_11_03_090530) do t.integer "housingneeds_g" t.integer "housingneeds_h" t.boolean "accessibility_requirements_prefer_not_to_say" - t.boolean "illness_type_1" - t.boolean "illness_type_2" - t.boolean "illness_type_3" - t.boolean "illness_type_4" - t.boolean "illness_type_8" - t.boolean "illness_type_5" - t.boolean "illness_type_6" - t.boolean "illness_type_7" - t.boolean "illness_type_9" - t.boolean "illness_type_10" + t.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 "rp_homeless" t.boolean "rp_insan_unsat" diff --git a/spec/controllers/case_logs_controller_spec.rb b/spec/controllers/case_logs_controller_spec.rb index 572183315..98333d0c7 100644 --- a/spec/controllers/case_logs_controller_spec.rb +++ b/spec/controllers/case_logs_controller_spec.rb @@ -66,18 +66,18 @@ RSpec.describe CaseLogsController, type: :controller do post :submit_form, params: { id: id, case_log: case_log_form_params } case_log.reload - expect(case_log.housingneeds_a).to eq(true) - expect(case_log.housingneeds_b).to eq(true) - expect(case_log.housingneeds_c).to eq(true) + expect(case_log.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.housingneeds_a).to eq(false) - expect(case_log.housingneeds_b).to eq(false) - expect(case_log.housingneeds_c).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 @@ -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.housingneeds_a).to eq(true) - expect(case_log.housingneeds_b).to eq(true) - expect(case_log.housingneeds_c).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 diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 2af5e0504..d392d67c0 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -84,8 +84,8 @@ RSpec.describe "Test Features" do let(:case_log_with_checkbox_questions_answered) do FactoryBot.create( :case_log, :in_progress, - housingneeds_a: true, - housingneeds_c: true + housingneeds_a: "Yes", + housingneeds_c: "Yes" ) end diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 56ae22c08..2ea30df95 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -40,7 +40,7 @@ "homeless": "Yes - other homelessness", "reason_for_leaving_last_settled_home": "Other problems with neighbours", "underoccupation_benefitcap": "No", - "leftreg": "No", + "leftreg": "No - they left up to 5 years ago", "reservist": "No", "armed_forces_partner": "No", "illness": "Yes", @@ -90,24 +90,24 @@ "cap": false, "outstanding_rent_or_charges": 25, "other_reason_for_leaving_last_settled_home": null, - "housingneeds_a": true, - "housingneeds_b": false, - "housingneeds_c": false, - "housingneeds_f": false, - "housingneeds_g": false, - "housingneeds_h": false, - "accessibility_requirements_prefer_not_to_say": false, - "illness_type_1": false, - "illness_type_2": true, - "illness_type_3": false, - "illness_type_4": false, - "illness_type_8": false, - "illness_type_5": false, - "illness_type_6": false, - "illness_type_7": false, - "illness_type_9": false, - "illness_type_10": false, - "condition_effects_prefer_not_to_say": true, + "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": false, "rp_insan_unsat": false, "rp_medwel": false,