Browse Source

Two questions that route to each other

pull/21/head
baarkerlounger 3 years ago
parent
commit
5b4fcb6317
  1. 17
      app/controllers/case_logs_controller.rb
  2. 24
      app/views/case_logs/edit.html.erb
  3. 8
      app/views/case_logs/household/tenant_age.html.erb
  4. 8
      app/views/case_logs/household/tenant_code.html.erb
  5. 12
      db/migrate/20210914101759_add_question_fields_to_case_logs.rb
  6. 10
      db/schema.rb
  7. 8
      spec/features/case_log_spec.rb

17
app/controllers/case_logs_controller.rb

@ -7,4 +7,21 @@ class CaseLogsController < ApplicationController
def show
@case_log = CaseLog.find(params[:id])
end
def edit
@case_log = CaseLog.find(params[:id])
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]
render_next_question(@case_log)
end
private
def render_next_question(case_log)
render 'case_logs/household/tenant_age'
end
end

24
app/views/case_logs/edit.html.erb

@ -1,8 +1,16 @@
<%= form_with model: @case_log, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_number_field :age,
hint: { text: "More detail" },
label: { text: "What is the tenant's age?", size: "l"},
min: 0, max: 150, step: 1, width: 20
%>
<%= f.govuk_submit %>
<% end %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">Tasklist for log
<%= @case_log.id %></h1>
<h2 class="govuk-heading-s govuk-!-margin-bottom-2">This submission is
<%= @case_log.status %></h2>
<p class="govuk-body govuk-!-margin-bottom-7">You've completed 0 of 9 sections.</p>
<p class="govuk-body govuk-!-margin-bottom-7">
<a href="#">Skip to next incomplete section</a>
</p>
<%= render "tasklist" %>
</div>
</div>

8
app/views/case_logs/household/tenant_age.html.erb

@ -0,0 +1,8 @@
<%= form_with model: @case_log, method: "patch", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_number_field :tenant_age,
hint: { text: "More detail" },
label: { text: "What is the tenant's age?", size: "l"},
min: 0, max: 150, step: 1, width: 20
%>
<%= f.govuk_submit "Save and continue" %>
<% end %>

8
app/views/case_logs/household/tenant_code.html.erb

@ -0,0 +1,8 @@
<%= form_with model: @case_log, method: "patch", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_text_field :tenant_code,
hint: { text: "More detail" },
label: { text: "What is the tenant code?", size: "l"},
width: 20
%>
<%= f.govuk_submit "Save and continue" %>
<% end %>

12
db/migrate/20210914101759_add_question_fields_to_case_logs.rb

@ -0,0 +1,12 @@
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
end
end

10
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_08_122819) do
ActiveRecord::Schema.define(version: 2021_09_14_101759) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -19,6 +19,14 @@ ActiveRecord::Schema.define(version: 2021_09_08_122819) do
t.integer "status", default: 0
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "tenant_code"
t.integer "tenant_age"
t.string "tenant_gender"
t.string "tenant_ethnic_group"
t.string "tenant_nationality"
t.string "previous_housing_situation"
t.integer "prior_homelessness"
t.string "armed_forces"
end
end

8
spec/features/case_log_spec.rb

@ -15,4 +15,12 @@ RSpec.describe "Test Features" do
expect(page).to have_field("age")
expect(page).to have_button("Continue")
end
it "displays the household questions when you click into that section" do
visit("/case_logs/#{id}")
click_link("Household characteristics")
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")
end
end

Loading…
Cancel
Save