Browse Source

Spec form answer saving and fix for other household members

pull/22/head
baarkerlounger 3 years ago
parent
commit
f59aba2476
  1. 6
      app/models/form.rb
  2. 29
      app/views/form/questions/economic_status.html.erb
  3. 6
      app/views/form/questions/household_number_of_other_members.html.erb
  4. 29
      app/views/form/questions/tenant_economic_status.html.erb
  5. 2
      app/views/form/questions/tenant_ethnic_group.html.erb
  6. 2
      app/views/form/questions/tenant_gender.html.erb
  7. 34
      app/views/form/questions/tenant_nationality.html.erb
  8. 6
      db/migrate/20210922154335_rename_tenant_fields.rb
  9. 6
      db/schema.rb
  10. 58
      spec/features/case_log_spec.rb

6
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

29
app/views/form/questions/economic_status.html.erb

@ -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 %>

6
app/views/form/questions/other_household_members.html.erb → 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 %>

29
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 %>

2
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" %>

2
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" %>

34
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" %>

6
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

6
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"

58
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

Loading…
Cancel
Save