Browse Source

household characteristics section questions, db migration and form flow tests added

pull/22/head
Matthew Phelan 3 years ago
parent
commit
025b56a6cc
  1. 3
      app/models/form.rb
  2. 26
      app/views/form/questions/economic_status.erb
  3. 17
      app/views/form/questions/other_household_members.erb
  4. 35
      app/views/form/questions/tenant_ethnic_group.erb
  5. 32
      app/views/form/questions/tenant_nationality.erb
  6. 36
      db/migrate/20210922103729_add_household_characteristics_to_case_logs.rb
  7. 32
      db/schema.rb
  8. 12
      spec/features/case_log_spec.rb

3
app/models/form.rb

@ -26,6 +26,9 @@ class Form < ApplicationRecord
"tenant_age" => "tenant_gender", "tenant_age" => "tenant_gender",
"tenant_gender" => "tenant_ethnic_group", "tenant_gender" => "tenant_ethnic_group",
"tenant_ethnic_group" => "tenant_nationality", "tenant_ethnic_group" => "tenant_nationality",
"tenant_nationality" => "economic_status",
"economic_status" => "other_household_members",
"other_household_members" => "other_household_members",
"previous_housing_situation" => "previous_housing_situation", "previous_housing_situation" => "previous_housing_situation",
}.freeze }.freeze

26
app/views/form/questions/economic_status.erb

@ -0,0 +1,26 @@
<% 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") %>
<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %>
Back
<% 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 %>

17
app/views/form/questions/other_household_members.erb

@ -0,0 +1,17 @@
<% previous_question = Form.previous_question("other_household_members") %>
<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %>
Back
<% 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_number_field :other_household_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 :case_log_id, value: case_log_id %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<% end %>

35
app/views/form/questions/tenant_ethnic_group.erb

@ -0,0 +1,35 @@
<% ethnic_groups = [
OpenStruct.new(id: 0, ethnicity: "White: English/Scottish/Welsh/Northern Irish/British"),
OpenStruct.new(id: 1, ethnicity: "White: Irish"),
OpenStruct.new(id: 2, ethnicity: "White: Gypsy/Irish Traveller"),
OpenStruct.new(id: 3, ethnicity: "White: Other"),
OpenStruct.new(id: 4, ethnicity: "Mixed: White & Black Caribbean"),
OpenStruct.new(id: 5, ethnicity: "Mixed: White & Black African"),
OpenStruct.new(id: 6, ethnicity: "Mixed: White & Asian"),
OpenStruct.new(id: 7, ethnicity: "Mixed: Other"),
OpenStruct.new(id: 8, ethnicity: "Asian or Asian British: Indian"),
OpenStruct.new(id: 9, ethnicity: "Asian or Asian British: Pakistani"),
OpenStruct.new(id: 10, ethnicity: "Asian or Asian British: Bangladeshi"),
OpenStruct.new(id: 11, ethnicity: "Asian or Asian British: Chinese"),
OpenStruct.new(id: 12, ethnicity: "Asian or Asian British: Other"),
OpenStruct.new(id: 13, ethnicity: "Black: Caribbean"),
OpenStruct.new(id: 14, ethnicity: "Black: African"),
OpenStruct.new(id: 15, ethnicity: "Black: Other"),
OpenStruct.new(id: 16, ethnicity: "Other Ethnic Group: Arab"),
OpenStruct.new(id: 17, ethnicity: "Other Ethnic Group: Other"),
OpenStruct.new(id: 18, ethnicity: "Prefer not to say")
] %>
<% previous_question = Form.previous_question("tenant_ethnic_group") %>
<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %>
Back
<% 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_ethnic_group, ethnic_groups, :id, :ethnicity, 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" %>
<% end %>
<% end %>

32
app/views/form/questions/tenant_nationality.erb

@ -0,0 +1,32 @@
<% 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")
] %>
<% previous_question = Form.previous_question("tenant_nationality") %>
<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %>
Back
<% 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_nationality, nationalities, :id, :ethnicity, 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" %>
<% end %>
<% end %>

36
db/migrate/20210922103729_add_household_characteristics_to_case_logs.rb

@ -0,0 +1,36 @@
class AddHouseholdCharacteristicsToCaseLogs < ActiveRecord::Migration[6.1]
def change
change_table :case_logs, bulk: true do |t|
t.column :economic_status, :string
t.column :number_of_other_members, :integer
t.column :person_2_relationship, :string
t.column :person_2_age, :integer
t.column :person_2_gender, :string
t.column :person_2_economic, :string
t.column :person_3_relationship, :string
t.column :person_3_age, :integer
t.column :person_3_gender, :string
t.column :person_3_economic, :string
t.column :person_4_relationship, :string
t.column :person_4_age, :integer
t.column :person_4_gender, :string
t.column :person_4_economic, :string
t.column :person_5_relationship, :string
t.column :person_5_age, :integer
t.column :person_5_gender, :string
t.column :person_5_economic, :string
t.column :person_6_relationship, :string
t.column :person_6_age, :integer
t.column :person_6_gender, :string
t.column :person_6_economic, :string
t.column :person_7_relationship, :string
t.column :person_7_age, :integer
t.column :person_7_gender, :string
t.column :person_7_economic, :string
t.column :person_8_relationship, :string
t.column :person_8_age, :integer
t.column :person_8_gender, :string
t.column :person_8_economic, :string
end
end
end

32
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_09_14_101759) do ActiveRecord::Schema.define(version: 2021_09_22_103729) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -27,6 +27,36 @@ ActiveRecord::Schema.define(version: 2021_09_14_101759) do
t.string "previous_housing_situation" t.string "previous_housing_situation"
t.integer "prior_homelessness" t.integer "prior_homelessness"
t.string "armed_forces" t.string "armed_forces"
t.string "economic_status"
t.integer "number_of_other_members"
t.string "person_2_relationship"
t.integer "person_2_age"
t.string "person_2_gender"
t.string "person_2_economic"
t.string "person_3_relationship"
t.integer "person_3_age"
t.string "person_3_gender"
t.string "person_3_economic"
t.string "person_4_relationship"
t.integer "person_4_age"
t.string "person_4_gender"
t.string "person_4_economic"
t.string "person_5_relationship"
t.integer "person_5_age"
t.string "person_5_gender"
t.string "person_5_economic"
t.string "person_6_relationship"
t.integer "person_6_age"
t.string "person_6_gender"
t.string "person_6_economic"
t.string "person_7_relationship"
t.integer "person_7_age"
t.string "person_7_gender"
t.string "person_7_economic"
t.string "person_8_relationship"
t.integer "person_8_age"
t.string "person_8_gender"
t.string "person_8_economic"
end end
end end

12
spec/features/case_log_spec.rb

@ -3,6 +3,7 @@ RSpec.describe "Test Features" do
let!(:case_log) { FactoryBot.create(:case_log) } let!(:case_log) { FactoryBot.create(:case_log) }
let(:id) { case_log.id } let(:id) { case_log.id }
let(:status) { case_log.status } let(:status) { case_log.status }
pages = ['tenant_code', 'tenant_age', 'tenant_gender', 'tenant_ethnic_group', 'tenant_nationality', 'economic_status', 'other_household_members']
describe "Create new log" do describe "Create new log" do
it "redirects to the task list for the new log" do it "redirects to the task list for the new log" do
@ -53,4 +54,15 @@ RSpec.describe "Test Features" do
expect(page).to have_field("tenant-code-field") expect(page).to have_field("tenant-code-field")
end end
end 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 {
|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

Loading…
Cancel
Save