diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 9eb4ec4c7..8283ca85c 100644 --- a/app/controllers/case_logs_controller.rb +++ b/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 +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 diff --git a/app/views/case_logs/household/tenant_gender.html.erb b/app/views/case_logs/household/tenant_gender.html.erb new file mode 100644 index 000000000..54aa49f28 --- /dev/null +++ b/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 %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d12a55a15..16521773c 100644 --- a/config/routes.rb +++ b/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 diff --git a/db/migrate/20210914101759_add_question_fields_to_case_logs.rb b/db/migrate/20210914101759_add_question_fields_to_case_logs.rb index c855c2392..13bc169db 100644 --- a/db/migrate/20210914101759_add_question_fields_to_case_logs.rb +++ b/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 diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index b2a4f6d6b..1aeb1cbb2 100644 --- a/spec/features/case_log_spec.rb +++ b/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