Browse Source

Added gender question

pull/21/head
baarkerlounger 3 years ago
parent
commit
02ceafa387
  1. 13
      app/controllers/case_logs_controller.rb
  2. 11
      app/views/case_logs/household/tenant_gender.html.erb
  3. 2
      config/routes.rb
  4. 18
      db/migrate/20210914101759_add_question_fields_to_case_logs.rb
  5. 2
      spec/features/case_log_spec.rb

13
app/controllers/case_logs_controller.rb

@ -10,18 +10,23 @@ class CaseLogsController < ApplicationController
def edit
@case_log = CaseLog.find(params[:id])
render 'case_logs/household/tenant_code'
render "case_logs/household/tenant_code"
end
def update
@case_log = CaseLog.find(params[:id])
@case_log.update(tenant_code: params[:case_log][:tenant_code]) if params[:case_log]
@case_log.update!(tenant_code: params[:case_log][:tenant_code]) if params[:case_log]
render_next_question(@case_log)
end
private
def render_next_question(case_log)
render 'case_logs/household/tenant_age'
def render_next_question(_case_log)
previous = params[:case_log].keys.first
next_question = {
"tenant_code" => "case_logs/household/tenant_age",
"tenant_age" => "case_logs/household/tenant_gender",
}[previous]
render next_question
end
end

11
app/views/case_logs/household/tenant_gender.html.erb

@ -0,0 +1,11 @@
<% genders = [
OpenStruct.new(id: 0, name: "Male"),
OpenStruct.new(id: 1, name: "Female"),
OpenStruct.new(id: 2, name: "Non-binary"),
OpenStruct.new(id: 3, name: "Prefer not to say")
] %>
<%= form_with model: @case_log, method: "patch", 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_submit "Save and continue" %>
<% end %>

2
config/routes.rb

@ -2,8 +2,6 @@ Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
get "about", to: "about#index"
get "/", to: "test#index"
get "form", to: "form#index"
get "age", to: "form#age"
resources :case_logs
end

18
db/migrate/20210914101759_add_question_fields_to_case_logs.rb

@ -1,12 +1,14 @@
class AddQuestionFieldsToCaseLogs < ActiveRecord::Migration[6.1]
def change
add_column :case_logs, :tenant_code, :string
add_column :case_logs, :tenant_age, :integer
add_column :case_logs, :tenant_gender, :string
add_column :case_logs, :tenant_ethnic_group, :string
add_column :case_logs, :tenant_nationality, :string
add_column :case_logs, :previous_housing_situation, :string
add_column :case_logs, :prior_homelessness, :integer
add_column :case_logs, :armed_forces, :string
change_table :case_logs, bulk: true do |t|
t.column :tenant_code, :string
t.column :tenant_age, :integer
t.column :tenant_gender, :string
t.column :tenant_ethnic_group, :string
t.column :tenant_nationality, :string
t.column :previous_housing_situation, :string
t.column :prior_homelessness, :integer
t.column :armed_forces, :string
end
end
end

2
spec/features/case_log_spec.rb

@ -22,5 +22,7 @@ RSpec.describe "Test Features" do
expect(page).to have_field("case-log-tenant-code-field")
click_button("Save and continue")
expect(page).to have_field("case-log-tenant-age-field")
click_button("Save and continue")
expect(page).to have_field("case-log-tenant-gender-0-field")
end
end

Loading…
Cancel
Save