From f59aba24760240798d2e48bff09204d687a443a2 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 22 Sep 2021 17:05:24 +0100 Subject: [PATCH] Spec form answer saving and fix for other household members --- app/models/form.rb | 6 +- .../form/questions/economic_status.html.erb | 29 ---------- ...ousehold_number_of_other_members.html.erb} | 6 +- .../questions/tenant_economic_status.html.erb | 29 ++++++++++ .../questions/tenant_ethnic_group.html.erb | 2 +- .../form/questions/tenant_gender.html.erb | 2 +- .../questions/tenant_nationality.html.erb | 34 +++++------ .../20210922154335_rename_tenant_fields.rb | 6 ++ db/schema.rb | 6 +- spec/features/case_log_spec.rb | 58 +++++++++++++++++-- 10 files changed, 115 insertions(+), 63 deletions(-) delete mode 100644 app/views/form/questions/economic_status.html.erb rename app/views/form/questions/{other_household_members.html.erb => household_number_of_other_members.html.erb} (73%) create mode 100644 app/views/form/questions/tenant_economic_status.html.erb create mode 100644 db/migrate/20210922154335_rename_tenant_fields.rb diff --git a/app/models/form.rb b/app/models/form.rb index 3ed172ace..008ca36d7 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -26,9 +26,9 @@ class Form < ApplicationRecord "tenant_age" => "tenant_gender", "tenant_gender" => "tenant_ethnic_group", "tenant_ethnic_group" => "tenant_nationality", - "tenant_nationality" => "economic_status", - "economic_status" => "other_household_members", - "other_household_members" => "other_household_members", + "tenant_nationality" => "tenant_economic_status", + "tenant_economic_status" => "household_number_of_other_members", + "household_number_of_other_members" => "household_number_of_other_members", "previous_housing_situation" => "previous_housing_situation", }.freeze diff --git a/app/views/form/questions/economic_status.html.erb b/app/views/form/questions/economic_status.html.erb deleted file mode 100644 index 4558cc54e..000000000 --- a/app/views/form/questions/economic_status.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -<% economic_statuses = [ - OpenStruct.new(id: 0, ethnicity: "Part-time - Less than 30 hours"), - OpenStruct.new(id: 1, ethnicity: "Full-time - 30 hours or more"), - OpenStruct.new(id: 2, ethnicity: "In government training into work, such as New Deal"), - OpenStruct.new(id: 3, ethnicity: "Jobseeker"), - OpenStruct.new(id: 4, ethnicity: "Retired"), - OpenStruct.new(id: 5, ethnicity: "Not seeking work"), - OpenStruct.new(id: 6, ethnicity: "Full-time student"), - OpenStruct.new(id: 7, ethnicity: "Unable to work because of long term sick or disability"), - OpenStruct.new(id: 8, ethnicity: "Child under 16"), - OpenStruct.new(id: 9, ethnicity: "Other"), - OpenStruct.new(id: 10, ethnicity: "Prefer not to say") -] %> - -<% previous_question = Form.previous_question("economic_status") %> -<% content_for :before_content do %> - <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %> - Back - <% end %> -<% end %> - -<%= turbo_frame_tag "case_log_form", target: "_top" do %> - <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_collection_radio_buttons :economic_status, economic_statuses, :id, :ethnicity, legend: { text: "Which of these best describes the tenant's working situation?", size: "l" } %> - <%= f.hidden_field :previous_question, value: :economic_status %> - <%= f.hidden_field :case_log_id, value: case_log_id %> - <%= f.govuk_submit "Save and continue" %> - <% end %> -<% end %> diff --git a/app/views/form/questions/other_household_members.html.erb b/app/views/form/questions/household_number_of_other_members.html.erb similarity index 73% rename from app/views/form/questions/other_household_members.html.erb rename to app/views/form/questions/household_number_of_other_members.html.erb index 335da40ed..4c70b3f1c 100644 --- a/app/views/form/questions/other_household_members.html.erb +++ b/app/views/form/questions/household_number_of_other_members.html.erb @@ -1,4 +1,4 @@ -<% previous_question = Form.previous_question("other_household_members") %> +<% previous_question = Form.previous_question("household_number_of_other_members") %> <% content_for :before_content do %> <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %> Back @@ -7,12 +7,12 @@ <%= turbo_frame_tag "case_log_form", target: "_top" do %> <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_number_field :other_household_members, + <%= f.govuk_number_field :household_number_of_other_members, hint: { text: "The maximum number of others is 7" }, label: { text: "How many other people are there in the household?", size: "l"}, min: 0, max: 7, step: 1, width: 20 %> - <%= f.hidden_field :previous_question, value: :other_household_members %> + <%= f.hidden_field :previous_question, value: :household_number_of_other_members %> <%= f.hidden_field :case_log_id, value: case_log_id %> <%= f.govuk_submit "Save and continue" %> <% end %> diff --git a/app/views/form/questions/tenant_economic_status.html.erb b/app/views/form/questions/tenant_economic_status.html.erb new file mode 100644 index 000000000..97b3a4347 --- /dev/null +++ b/app/views/form/questions/tenant_economic_status.html.erb @@ -0,0 +1,29 @@ +<% economic_statuses = [ + OpenStruct.new(id: 0, economic_status: "Part-time - Less than 30 hours"), + OpenStruct.new(id: 1, economic_status: "Full-time - 30 hours or more"), + OpenStruct.new(id: 2, economic_status: "In government training into work, such as New Deal"), + OpenStruct.new(id: 3, economic_status: "Jobseeker"), + OpenStruct.new(id: 4, economic_status: "Retired"), + OpenStruct.new(id: 5, economic_status: "Not seeking work"), + OpenStruct.new(id: 6, economic_status: "Full-time student"), + OpenStruct.new(id: 7, economic_status: "Unable to work because of long term sick or disability"), + OpenStruct.new(id: 8, economic_status: "Child under 16"), + OpenStruct.new(id: 9, economic_status: "Other"), + OpenStruct.new(id: 10, economic_status: "Prefer not to say") +] %> + +<% previous_question = Form.previous_question("tenant_economic_status") %> +<% content_for :before_content do %> + <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %> + Back + <% end %> +<% end %> + +<%= turbo_frame_tag "case_log_form", target: "_top" do %> + <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <%= f.govuk_collection_radio_buttons :tenant_economic_status, economic_statuses, :id, legend: { text: "Which of these best describes the tenant's working situation?", size: "l" } %> + <%= f.hidden_field :previous_question, value: :tenant_economic_status %> + <%= f.hidden_field :case_log_id, value: case_log_id %> + <%= f.govuk_submit "Save and continue" %> + <% end %> +<% end %> diff --git a/app/views/form/questions/tenant_ethnic_group.html.erb b/app/views/form/questions/tenant_ethnic_group.html.erb index 233861f8f..d3f2c356d 100644 --- a/app/views/form/questions/tenant_ethnic_group.html.erb +++ b/app/views/form/questions/tenant_ethnic_group.html.erb @@ -30,7 +30,7 @@ <%= turbo_frame_tag "case_log_form", target: "_top" do %> <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_collection_radio_buttons :tenant_ethnic_group, ethnic_groups, :id, :ethnicity, legend: { text: "What is the tenant’s ethnic group?", size: "l" } %> + <%= f.govuk_collection_radio_buttons :tenant_ethnic_group, ethnic_groups, :id, legend: { text: "What is the tenant’s ethnic group?", size: "l" } %> <%= f.hidden_field :previous_question, value: :tenant_ethnic_group %> <%= f.hidden_field :case_log_id, value: case_log_id %> <%= f.govuk_submit "Save and continue" %> diff --git a/app/views/form/questions/tenant_gender.html.erb b/app/views/form/questions/tenant_gender.html.erb index e01b7aa41..35e6b01f7 100644 --- a/app/views/form/questions/tenant_gender.html.erb +++ b/app/views/form/questions/tenant_gender.html.erb @@ -14,7 +14,7 @@ <%= turbo_frame_tag "case_log_form", target: "_top" do %> <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_collection_radio_buttons :tenant_gender, genders, :id, :name, legend: { text: "Which of these best describes the tenant's gender identity?", size: "l" } %> + <%= f.govuk_collection_radio_buttons :tenant_gender, genders, :id, legend: { text: "Which of these best describes the tenant's gender identity?", size: "l" } %> <%= f.hidden_field :previous_question, value: :tenant_gender %> <%= f.hidden_field :case_log_id, value: case_log_id %> <%= f.govuk_submit "Save and continue" %> diff --git a/app/views/form/questions/tenant_nationality.html.erb b/app/views/form/questions/tenant_nationality.html.erb index 61c7e5cc1..0a3ded5fb 100644 --- a/app/views/form/questions/tenant_nationality.html.erb +++ b/app/views/form/questions/tenant_nationality.html.erb @@ -1,20 +1,20 @@ <% nationalities = [ - OpenStruct.new(id: 0, ethnicity: "UK national resident in UK"), - OpenStruct.new(id: 1, ethnicity: "A current or former reserve in the UK Armed Forces (exc. National Service)"), - OpenStruct.new(id: 2, ethnicity: "UK national returning from residence overseas"), - OpenStruct.new(id: 3, ethnicity: "Czech Republic"), - OpenStruct.new(id: 4, ethnicity: "Estonia"), - OpenStruct.new(id: 5, ethnicity: "Hungary"), - OpenStruct.new(id: 6, ethnicity: "Latvia"), - OpenStruct.new(id: 7, ethnicity: "Lithuania"), - OpenStruct.new(id: 8, ethnicity: "Poland"), - OpenStruct.new(id: 9, ethnicity: "Slovakia"), - OpenStruct.new(id: 10, ethnicity: "Bulgaria"), - OpenStruct.new(id: 11, ethnicity: "Romania"), - OpenStruct.new(id: 12, ethnicity: "Ireland"), - OpenStruct.new(id: 13, ethnicity: "Other EU Economic Area (EEA country)"), - OpenStruct.new(id: 14, ethnicity: "Any other country"), - OpenStruct.new(id: 15, ethnicity: "Prefer not to say") + OpenStruct.new(id: 0, nationality: "UK national resident in UK"), + OpenStruct.new(id: 1, nationality: "A current or former reserve in the UK Armed Forces (exc. National Service)"), + OpenStruct.new(id: 2, nationality: "UK national returning from residence overseas"), + OpenStruct.new(id: 3, nationality: "Czech Republic"), + OpenStruct.new(id: 4, nationality: "Estonia"), + OpenStruct.new(id: 5, nationality: "Hungary"), + OpenStruct.new(id: 6, nationality: "Latvia"), + OpenStruct.new(id: 7, nationality: "Lithuania"), + OpenStruct.new(id: 8, nationality: "Poland"), + OpenStruct.new(id: 9, nationality: "Slovakia"), + OpenStruct.new(id: 10, nationality: "Bulgaria"), + OpenStruct.new(id: 11, nationality: "Romania"), + OpenStruct.new(id: 12, nationality: "Ireland"), + OpenStruct.new(id: 13, nationality: "Other EU Economic Area (EEA country)"), + OpenStruct.new(id: 14, nationality: "Any other country"), + OpenStruct.new(id: 15, nationality: "Prefer not to say") ] %> <% previous_question = Form.previous_question("tenant_nationality") %> @@ -26,7 +26,7 @@ <%= turbo_frame_tag "case_log_form", target: "_top" do %> <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_collection_radio_buttons :tenant_nationality, nationalities, :id, :ethnicity, legend: { text: "What is the tenant’s ethnic group?", size: "l" } %> + <%= f.govuk_collection_radio_buttons :tenant_nationality, nationalities, :id, legend: { text: "What is the tenant’s ethnic group?", size: "l" } %> <%= f.hidden_field :previous_question, value: :tenant_nationality %> <%= f.hidden_field :case_log_id, value: case_log_id %> <%= f.govuk_submit "Save and continue" %> diff --git a/db/migrate/20210922154335_rename_tenant_fields.rb b/db/migrate/20210922154335_rename_tenant_fields.rb new file mode 100644 index 000000000..e35f58b0f --- /dev/null +++ b/db/migrate/20210922154335_rename_tenant_fields.rb @@ -0,0 +1,6 @@ +class RenameTenantFields < ActiveRecord::Migration[6.1] + def change + rename_column :case_logs, :economic_status, :tenant_economic_status + rename_column :case_logs, :number_of_other_members, :household_number_of_other_members + end +end diff --git a/db/schema.rb b/db/schema.rb index 7d2d8b835..9186f502c 100644 --- a/db/schema.rb +++ b/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_09_22_103729) do +ActiveRecord::Schema.define(version: 2021_09_22_154335) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -28,8 +28,8 @@ ActiveRecord::Schema.define(version: 2021_09_22_103729) do t.integer "prior_homelessness" t.string "armed_forces" t.string "postcode" - t.string "economic_status" - t.integer "number_of_other_members" + t.string "tenant_economic_status" + t.integer "household_number_of_other_members" t.string "person_2_relationship" t.integer "person_2_age" t.string "person_2_gender" diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index fefb89288..c7888802b 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "Test Features" do let!(:case_log) { FactoryBot.create(:case_log, :in_progress) } let(:id) { case_log.id } let(:status) { case_log.status } - pages = %w[tenant_code tenant_age tenant_gender tenant_ethnic_group tenant_nationality economic_status other_household_members] + pages = %w[tenant_code tenant_age tenant_gender tenant_ethnic_group tenant_nationality tenant_economic_status household_number_of_other_members] describe "Create new log" do it "redirects to the task list for the new log" do @@ -38,6 +38,50 @@ RSpec.describe "Test Features" do visit("/case_logs/#{id}/tenant_age") expect(page).to have_field("tenant-age-field") end + + it "updates model attributes correctly for each question" do + visit("/case_logs/#{id}/tenant_code") + fill_in(:tenant_code, with: "BZ737") + expect { click_button("Save and continue") }.to change { + case_log.reload.tenant_code + }.from("TH356").to("BZ737") + + visit("/case_logs/#{id}/tenant_age") + fill_in(:tenant_age, with: 25) + expect { click_button("Save and continue") }.to change { + case_log.reload.tenant_age + }.from(NilClass).to(25) + + visit("/case_logs/#{id}/tenant_gender") + choose("tenant-gender-1-field") + expect { click_button("Save and continue") }.to change { + case_log.reload.tenant_gender + }.from(NilClass).to("1") + + visit("/case_logs/#{id}/tenant_ethnic_group") + choose("tenant-ethnic-group-2-field") + expect { click_button("Save and continue") }.to change { + case_log.reload.tenant_ethnic_group + }.from(NilClass).to("2") + + visit("/case_logs/#{id}/tenant_nationality") + choose("tenant-nationality-0-field") + expect { click_button("Save and continue") }.to change { + case_log.reload.tenant_nationality + }.from(NilClass).to("0") + + visit("/case_logs/#{id}/tenant_economic_status") + choose("tenant-economic-status-4-field") + expect { click_button("Save and continue") }.to change { + case_log.reload.tenant_economic_status + }.from(NilClass).to("4") + + visit("/case_logs/#{id}/household_number_of_other_members") + fill_in(:household_number_of_other_members, with: 2) + expect { click_button("Save and continue") }.to change { + case_log.reload.household_number_of_other_members + }.from(NilClass).to(2) + end end describe "Back link directs correctly" do @@ -56,11 +100,13 @@ RSpec.describe "Test Features" do end describe "Form flow is correct" do - it "given an ordered list of pages make sure each leads to the next one in order" do - pages[0..-2].each_with_index do |val, index| - visit("/case_logs/#{id}/#{val}") - click_button("Save and continue") - expect(page).to have_current_path("/case_logs/#{id}/#{pages[index + 1]}") + context "given an ordered list of pages" do + it "leads to the next one in the correct order" do + pages[0..-2].each_with_index do |val, index| + visit("/case_logs/#{id}/#{val}") + click_button("Save and continue") + expect(page).to have_current_path("/case_logs/#{id}/#{pages[index + 1]}") + end end end end