Browse Source

Merge branch 'main' into CLDC-344/Implement-a-few-validations

pull/39/head
Matthew Phelan 3 years ago
parent
commit
b907946ac6
  1. 2
      README.md
  2. 20
      app/controllers/case_logs_controller.rb
  3. 2
      app/views/case_logs/_log_list.html.erb
  4. 6
      app/views/form/_checkbox_question.html.erb
  5. 46
      config/forms/2021_2022.json
  6. 13
      db/migrate/20211008130122_add_accessibility_fields.rb
  7. 17
      db/migrate/20211008130149_add_condition_effects_fields.rb
  8. 11
      db/migrate/20211008130208_add_reasonable_preference_reason_fields.rb
  9. 14
      db/migrate/20211011115946_rename_economic_status_fields.rb
  10. 41
      db/schema.rb
  11. 80
      spec/controllers/case_logs_controller_spec.rb
  12. 4
      spec/factories/case_log.rb
  13. 29
      spec/features/case_log_spec.rb
  14. 2
      spec/helpers/tasklist_helper_spec.rb
  15. 4
      spec/views/case_log_index_view_spec.rb

2
README.md

@ -133,7 +133,7 @@ Assumptions made by the format:
- All sections have at least 1 subsection
- All subsections have at least 1 page
- All pages have at least 1 question
- The ActiveRecord case log model has a field for each question name (must match)
- The ActiveRecord case log model has a field for each question name (must match). In the case of checkbox questions it must have one field for every answer option (again names must match).
- Text not required by a page/question such as a header or hint text should be passed as an empty string
- For conditionally shown questions conditions that have been implemented and can be used are:
- Radio question answer option selected matches one of conditional e.g. ["answer-options-1-string", "answer-option-3-string"]

20
app/controllers/case_logs_controller.rb

@ -24,10 +24,10 @@ class CaseLogsController < ApplicationController
form = Form.new(2021, 2022)
@case_log = CaseLog.find(params[:id])
previous_page = params[:case_log][:previous_page]
questions_for_page = form.questions_for_page(previous_page).keys
answers_for_page = page_params(questions_for_page).select { |k, _v| questions_for_page.include?(k) }
questions_for_page = form.questions_for_page(previous_page)
responses_for_page = question_responses(questions_for_page)
@case_log.previous_page = previous_page
if @case_log.update(answers_for_page)
if @case_log.update(responses_for_page)
redirect_path = form.next_page_redirect_path(previous_page)
redirect_to(send(redirect_path, @case_log))
else
@ -53,7 +53,17 @@ class CaseLogsController < ApplicationController
private
def page_params(questions_for_page)
params.require(:case_log).permit(questions_for_page)
def question_responses(questions_for_page)
questions_for_page.each_with_object({}) do |(question_key, question_info), result|
question_params = params["case_log"][question_key]
if question_info["type"] == "checkbox"
question_info["answer_options"].keys.reject { |x| x.match(/divider/) }.each do |option|
result[option] = question_params.include?(option)
end
else
result[question_key] = question_params
end
result
end
end
end

2
app/views/case_logs/_log_list.html.erb

@ -15,7 +15,7 @@
<%= link_to log.id, case_log_path(log) %>
</th>
<td class="govuk-table__cell govuk-table__cell">
<%= log.postcode %>
<%= log.property_postcode %>
</td>
<td class="govuk-table__cell govuk-table__cell">
<%= log.tenant_code %>

6
app/views/form/_checkbox_question.html.erb

@ -6,7 +6,11 @@
<% if key.starts_with?("divider") %>
<%= f.govuk_check_box_divider %>
<% else %>
<%= f.govuk_check_box question_key, val, label: { text: val }, **stimulus_html_attributes(question) %>
<%= f.govuk_check_box question_key, key,
label: { text: val },
checked: f.object.send(key),
**stimulus_html_attributes(question)
%>
<% end %>
<% end %>
<% end %>

46
config/forms/2021_2022.json

@ -783,15 +783,15 @@
"type": "checkbox",
"check_answer_label": "Disability requirements",
"answer_options": {
"0": "Fully wheelchair accessible housing",
"1": "Wheelchair access to essential rooms",
"2": "Level access housing",
"3": "Other disability requirements",
"4": "No disability requirements",
"accessibility_requirements_fully_wheelchair_accessible_housing": "Fully wheelchair accessible housing",
"accessibility_requirements_wheelchair_access_to_essential_rooms": "Wheelchair access to essential rooms",
"accessibility_requirements_level_access_housing": "Level access housing",
"accessibility_requirements_other_disability_requirements": "Other disability requirements",
"accessibility_requirements_no_disability_requirements": "No disability requirements",
"divider_a": true,
"5": "Do not know",
"accessibility_requirements_do_not_know": "Do not know",
"divider_b": true,
"6": "Prefer not to say"
"accessibility_requirements_prefer_not_to_say": "Prefer not to say"
}
}
}
@ -806,18 +806,18 @@
"type": "checkbox",
"check_answer_label": "Conditions or illnesses",
"answer_options": {
"0": "Vision - such as blindness or partial sight",
"1": "Hearing - such as deafness or partial hearing",
"2": "Mobility - such as walking short distances or climbing stairs",
"3": "Dexterity - such as lifting and carrying objects or using a keyboard",
"4": "Stamina or breathing or fatigue",
"5": "Learning or understanding or concentrating",
"6": "Memory",
"7": "Mental health - such as depression, anxiety, schizophrenia or bipolar",
"8": "Socially or behaviourally - such as those associated with autism spectral disorder (ASD) including Aspergers’ or attention deficit hyperactivity disorder (ADHD))",
"9": "Other",
"condition_effects_vision": "Vision - such as blindness or partial sight",
"condition_effects_hearing": "Hearing - such as deafness or partial hearing",
"condition_effects_mobility": "Mobility - such as walking short distances or climbing stairs",
"condition_effects_dexterity": "Dexterity - such as lifting and carrying objects or using a keyboard",
"condition_effects_stamina": "Stamina or breathing or fatigue",
"condition_effects_learning": "Learning or understanding or concentrating",
"condition_effects_memory": "Memory",
"condition_effects_mental_health": "Mental health - such as depression, anxiety, schizophrenia or bipolar",
"condition_effects_social_or_behavioral": "Socially or behaviourally - such as those associated with autism spectral disorder (ASD) including Aspergers’ or attention deficit hyperactivity disorder (ADHD))",
"condition_effects_other": "Other",
"divider": true,
"10": "Prefer not to say"
"condition_effects_prefer_not_to_say": "Prefer not to say"
}
}
}
@ -2025,12 +2025,12 @@
"hint_text": "Select all that apply",
"type": "checkbox",
"answer_options": {
"0": "Homeless or about to lose their home (within 56 days)",
"1": "Living in insanitary or overcrowded or unsatisfactory housing",
"2": "A need to move on medical and welfare grounds (including a disability)",
"3": "A need to move to avoid hardship to themselves or others",
"reasonable_preference_reason_homeless": "Homeless or about to lose their home (within 56 days)",
"reasonable_preference_reason_unsatisfactory_housing": "Living in insanitary or overcrowded or unsatisfactory housing",
"reasonable_preference_reason_medical_grounds": "A need to move on medical and welfare grounds (including a disability)",
"reasonable_preference_reason_avoid_hardship": "A need to move to avoid hardship to themselves or others",
"divider": true,
"4": "Do not know"
"reasonable_preference_reason_do_not_know": "Do not know"
}
}
}

13
db/migrate/20211008130122_add_accessibility_fields.rb

@ -0,0 +1,13 @@
class AddAccessibilityFields < ActiveRecord::Migration[6.1]
def change
change_table :case_logs, bulk: true do |t|
t.column :accessibility_requirements_fully_wheelchair_accessible_housing, :boolean
t.column :accessibility_requirements_wheelchair_access_to_essential_rooms, :boolean
t.column :accessibility_requirements_level_access_housing, :boolean
t.column :accessibility_requirements_other_disability_requirements, :boolean
t.column :accessibility_requirements_no_disability_requirements, :boolean
t.column :accessibility_requirements_do_not_know, :boolean
t.column :accessibility_requirements_prefer_not_to_say, :boolean
end
end
end

17
db/migrate/20211008130149_add_condition_effects_fields.rb

@ -0,0 +1,17 @@
class AddConditionEffectsFields < ActiveRecord::Migration[6.1]
def change
change_table :case_logs, bulk: true do |t|
t.column :condition_effects_vision, :boolean
t.column :condition_effects_hearing, :boolean
t.column :condition_effects_mobility, :boolean
t.column :condition_effects_dexterity, :boolean
t.column :condition_effects_stamina, :boolean
t.column :condition_effects_learning, :boolean
t.column :condition_effects_memory, :boolean
t.column :condition_effects_mental_health, :boolean
t.column :condition_effects_social_or_behavioral, :boolean
t.column :condition_effects_other, :boolean
t.column :condition_effects_prefer_not_to_say, :boolean
end
end
end

11
db/migrate/20211008130208_add_reasonable_preference_reason_fields.rb

@ -0,0 +1,11 @@
class AddReasonablePreferenceReasonFields < ActiveRecord::Migration[6.1]
def change
change_table :case_logs, bulk: true do |t|
t.column :reasonable_preference_reason_homeless, :boolean
t.column :reasonable_preference_reason_unsatisfactory_housing, :boolean
t.column :reasonable_preference_reason_medical_grounds, :boolean
t.column :reasonable_preference_reason_avoid_hardship, :boolean
t.column :reasonable_preference_reason_do_not_know, :boolean
end
end
end

14
db/migrate/20211011115946_rename_economic_status_fields.rb

@ -0,0 +1,14 @@
class RenameEconomicStatusFields < ActiveRecord::Migration[6.1]
def change
change_table :case_logs, bulk: true do |t|
t.rename :person_2_economic, :person_2_economic_status
t.rename :person_3_economic, :person_3_economic_status
t.rename :person_4_economic, :person_4_economic_status
t.rename :person_5_economic, :person_5_economic_status
t.rename :person_6_economic, :person_6_economic_status
t.rename :person_7_economic, :person_7_economic_status
t.rename :person_8_economic, :person_8_economic_status
t.rename :postcode, :property_postcode
end
end
end

41
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_10_05_115813) do
ActiveRecord::Schema.define(version: 2021_10_11_115946) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -32,31 +32,31 @@ ActiveRecord::Schema.define(version: 2021_10_05_115813) do
t.string "person_2_relationship"
t.integer "person_2_age"
t.string "person_2_gender"
t.string "person_2_economic"
t.string "person_2_economic_status"
t.string "person_3_relationship"
t.integer "person_3_age"
t.string "person_3_gender"
t.string "person_3_economic"
t.string "person_3_economic_status"
t.string "person_4_relationship"
t.integer "person_4_age"
t.string "person_4_gender"
t.string "person_4_economic"
t.string "person_4_economic_status"
t.string "person_5_relationship"
t.integer "person_5_age"
t.string "person_5_gender"
t.string "person_5_economic"
t.string "person_5_economic_status"
t.string "person_6_relationship"
t.integer "person_6_age"
t.string "person_6_gender"
t.string "person_6_economic"
t.string "person_6_economic_status"
t.string "person_7_relationship"
t.integer "person_7_age"
t.string "person_7_gender"
t.string "person_7_economic"
t.string "person_7_economic_status"
t.string "person_8_relationship"
t.integer "person_8_age"
t.string "person_8_gender"
t.string "person_8_economic"
t.string "person_8_economic_status"
t.string "postcode"
t.string "homelessness"
t.string "reason_for_leaving_last_settled_home"
@ -102,7 +102,6 @@ ActiveRecord::Schema.define(version: 2021_10_05_115813) do
t.string "time_lived_in_la"
t.string "time_on_la_waiting_list"
t.string "previous_la"
t.string "property_postcode"
t.string "reasonable_preference"
t.string "reasonable_preference_reason"
t.string "cbl_letting"
@ -110,6 +109,30 @@ ActiveRecord::Schema.define(version: 2021_10_05_115813) do
t.string "cap_letting"
t.string "outstanding_rent_or_charges"
t.string "other_reason_for_leaving_last_settled_home"
t.boolean "accessibility_requirements_fully_wheelchair_accessible_housing"
t.boolean "accessibility_requirements_wheelchair_access_to_essential_rooms"
t.boolean "accessibility_requirements_level_access_housing"
t.boolean "accessibility_requirements_other_disability_requirements"
t.boolean "accessibility_requirements_no_disability_requirements"
t.boolean "accessibility_requirements_do_not_know"
t.boolean "accessibility_requirements_prefer_not_to_say"
t.boolean "condition_effects_vision"
t.boolean "condition_effects_hearing"
t.boolean "condition_effects_mobility"
t.boolean "condition_effects_dexterity"
t.boolean "condition_effects_stamina"
t.boolean "condition_effects_learning"
t.boolean "condition_effects_memory"
t.boolean "condition_effects_mental_health"
t.boolean "condition_effects_social_or_behavioral"
t.boolean "condition_effects_other"
t.boolean "condition_effects_prefer_not_to_say"
t.boolean "reasonable_preference_reason_homeless"
t.boolean "reasonable_preference_reason_unsatisfactory_housing"
t.boolean "reasonable_preference_reason_medical_grounds"
t.boolean "reasonable_preference_reason_avoid_hardship"
t.boolean "reasonable_preference_reason_do_not_know"
t.string "property_postcode"
end
end

80
spec/controllers/case_logs_controller_spec.rb

@ -43,4 +43,84 @@ RSpec.describe CaseLogsController, type: :controller do
end
end
end
describe "submit_form" do
let!(:case_log) { FactoryBot.create(:case_log) }
let(:id) { case_log.id }
let(:case_log_form_params) do
{ accessibility_requirements:
%w[ accessibility_requirements_fully_wheelchair_accessible_housing
accessibility_requirements_wheelchair_access_to_essential_rooms
accessibility_requirements_level_access_housing],
previous_page: "accessibility_requirements" }
end
let(:new_case_log_form_params) do
{
accessibility_requirements: %w[accessibility_requirements_level_access_housing],
previous_page: "accessibility_requirements",
}
end
it "sets checked items to true" do
post :submit_form, params: { id: id, case_log: case_log_form_params }
case_log.reload
expect(case_log.accessibility_requirements_fully_wheelchair_accessible_housing).to eq(true)
expect(case_log.accessibility_requirements_wheelchair_access_to_essential_rooms).to eq(true)
expect(case_log.accessibility_requirements_level_access_housing).to eq(true)
end
it "sets previously submitted items to false when resubmitted with new values" do
post :submit_form, params: { id: id, case_log: new_case_log_form_params }
case_log.reload
expect(case_log.accessibility_requirements_fully_wheelchair_accessible_housing).to eq(false)
expect(case_log.accessibility_requirements_wheelchair_access_to_essential_rooms).to eq(false)
expect(case_log.accessibility_requirements_level_access_housing).to eq(true)
end
context "given a page with checkbox and non-checkbox questions" do
let(:tenant_code) { "BZ355" }
let(:case_log_form_params) do
{ accessibility_requirements:
%w[ accessibility_requirements_fully_wheelchair_accessible_housing
accessibility_requirements_wheelchair_access_to_essential_rooms
accessibility_requirements_level_access_housing],
tenant_code: tenant_code,
previous_page: "accessibility_requirements" }
end
let(:questions_for_page) do
{ "accessibility_requirements" =>
{
"type" => "checkbox",
"answer_options" =>
{ "accessibility_requirements_fully_wheelchair_accessible_housing" => "Fully wheelchair accessible housing",
"accessibility_requirements_wheelchair_access_to_essential_rooms" => "Wheelchair access to essential rooms",
"accessibility_requirements_level_access_housing" => "Level access housing",
"accessibility_requirements_other_disability_requirements" => "Other disability requirements",
"accessibility_requirements_no_disability_requirements" => "No disability requirements",
"divider_a" => true,
"accessibility_requirements_do_not_know" => "Do not know",
"divider_b" => true,
"accessibility_requirements_prefer_not_to_say" => "Prefer not to say" },
},
"tenant_code" =>
{
"type" => "text",
} }
end
it "updates both question fields" do
allow_any_instance_of(Form).to receive(:questions_for_page).and_return(questions_for_page)
post :submit_form, params: { id: id, case_log: case_log_form_params }
case_log.reload
expect(case_log.accessibility_requirements_fully_wheelchair_accessible_housing).to eq(true)
expect(case_log.accessibility_requirements_wheelchair_access_to_essential_rooms).to eq(true)
expect(case_log.accessibility_requirements_level_access_housing).to eq(true)
expect(case_log.tenant_code).to eq(tenant_code)
end
end
end
end

4
spec/factories/case_log.rb

@ -4,14 +4,14 @@ FactoryBot.define do
trait :in_progress do
status { 0 }
tenant_code { "TH356" }
postcode { "SW2 6HI" }
property_postcode { "SW2 6HI" }
previous_postcode { "P0 5ST" }
tenant_age { "12" }
end
trait :submitted do
status { 1 }
tenant_code { "BZ737" }
postcode { "NW1 7TY" }
property_postcode { "NW1 7TY" }
end
created_at { Time.zone.now }
updated_at { Time.zone.now }

29
spec/features/case_log_spec.rb

@ -96,6 +96,14 @@ RSpec.describe "Test Features" do
end
describe "form questions" do
let(:case_log_with_checkbox_questions_answered) do
FactoryBot.create(
:case_log, :in_progress,
accessibility_requirements_fully_wheelchair_accessible_housing: true,
accessibility_requirements_level_access_housing: true
)
end
it "can be accessed by url" do
visit("/case_logs/#{id}/tenant_age")
expect(page).to have_field("case-log-tenant-age-field")
@ -146,6 +154,23 @@ RSpec.describe "Test Features" do
visit("/case_logs/#{id}/tenant_age")
expect(page).to have_field("case-log-tenant-age-field", with: "12")
end
it "displays checkbox answers in inputs if they are already saved" do
visit("/case_logs/#{case_log_with_checkbox_questions_answered.id}/accessibility_requirements")
# Something about our styling makes the selenium webdriver think the actual radio buttons are not visible so we pass false here
expect(page).to have_checked_field(
"case-log-accessibility-requirements-accessibility-requirements-fully-wheelchair-accessible-housing-field",
visible: false,
)
expect(page).to have_unchecked_field(
"case-log-accessibility-requirements-accessibility-requirements-wheelchair-access-to-essential-rooms-field",
visible: false,
)
expect(page).to have_checked_field(
"case-log-accessibility-requirements-accessibility-requirements-level-access-housing-field",
visible: false,
)
end
end
describe "Back link directs correctly" do
@ -258,11 +283,11 @@ RSpec.describe "Test Features" do
choose("case-log-armed-forces-yes-a-regular-field", allow_label_click: true)
expect(page).to have_selector("#armed_forces_injured_div")
choose("case-log-armed-forces-injured-no-field", allow_label_click: true)
expect(find_field("case-log-armed-forces-injured-no-field", visible: false).checked?).to be_truthy
expect(page).to have_checked_field("case-log-armed-forces-injured-no-field", visible: false)
choose("case-log-armed-forces-no-field", allow_label_click: true)
expect(page).not_to have_selector("#armed_forces_injured_div")
choose("case-log-armed-forces-yes-a-regular-field", allow_label_click: true)
expect(find_field("case-log-armed-forces-injured-no-field", visible: false).checked?).to be_falsey
expect(page).to have_unchecked_field("case-log-armed-forces-injured-no-field", visible: false)
end
end
end

2
spec/helpers/tasklist_helper_spec.rb

@ -73,7 +73,7 @@ RSpec.describe TasklistHelper do
it "returns the number of sections in progress" do
@form = Form.new(2021, 2022)
expect(get_sections_count(@form, case_log, :in_progress)).to eq(2)
expect(get_sections_count(@form, case_log, :in_progress)).to eq(3)
end
it "returns 0 for invalid state" do

4
spec/views/case_log_index_view_spec.rb

@ -12,7 +12,7 @@ RSpec.describe "case_logs/index" do
expect(rendered).to match(/Logs you need to complete/)
expect(rendered).not_to match(/Logs you&#39;ve submitted/)
expect(rendered).to match(in_progress_log.tenant_code)
expect(rendered).to match(in_progress_log.postcode)
expect(rendered).to match(in_progress_log.property_postcode)
end
end
@ -25,7 +25,7 @@ RSpec.describe "case_logs/index" do
expect(rendered).to match(/Logs you&#39;ve submitted/)
expect(rendered).not_to match(/Logs you need to complete/)
expect(rendered).to match(submitted_log.tenant_code)
expect(rendered).to match(submitted_log.postcode)
expect(rendered).to match(submitted_log.property_postcode)
end
end

Loading…
Cancel
Save