Browse Source

Cldc 478 accessibility requirements validation (#163)

* Validate accessibility requirements

* update missing mappings
pull/162/head^2
kosiakkatrina 3 years ago committed by GitHub
parent
commit
58fc5982eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/case_log.rb
  2. 2
      app/models/constants/case_log.rb
  3. 10
      app/models/validations/household_validations.rb
  4. 5
      spec/features/form/saving_data_spec.rb
  5. 55
      spec/models/case_log_spec.rb
  6. 13
      spec/requests/form_controller_spec.rb

1
app/models/case_log.rb

@ -68,6 +68,7 @@ class CaseLog < ApplicationRecord
enum housingneeds_f: POLAR, _suffix: true enum housingneeds_f: POLAR, _suffix: true
enum housingneeds_g: POLAR, _suffix: true enum housingneeds_g: POLAR, _suffix: true
enum housingneeds_h: POLAR, _suffix: true enum housingneeds_h: POLAR, _suffix: true
enum accessibility_requirements_prefer_not_to_say: POLAR, _suffix: true
enum illness_type_1: POLAR, _suffix: true enum illness_type_1: POLAR, _suffix: true
enum illness_type_2: POLAR, _suffix: true enum illness_type_2: POLAR, _suffix: true
enum illness_type_3: POLAR, _suffix: true enum illness_type_3: POLAR, _suffix: true

2
app/models/constants/case_log.rb

@ -65,7 +65,7 @@ module Constants::CaseLog
ILLNESS = { ILLNESS = {
"Yes" => 1, "Yes" => 1,
"No" => 2, "No" => 2,
"Do not know" => 3, "Prefer not to say" => 3,
}.freeze }.freeze
LEFTREG = { LEFTREG = {

10
app/models/validations/household_validations.rb

@ -74,6 +74,16 @@ module Validations::HouseholdValidations
validate_person_age_matches_economic_status(record, 1) validate_person_age_matches_economic_status(record, 1)
end end
def validate_accessibility_requirements(record)
all_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c, record.housingneeds_f, record.housingneeds_g, record.housingneeds_h, record.accessibility_requirements_prefer_not_to_say]
if all_options.count("Yes") > 1
mobility_accessibility_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c]
unless all_options.count("Yes") == 2 && record.housingneeds_f == "Yes" && mobility_accessibility_options.any? { |x| x == "Yes" }
record.errors.add :housingneeds_a, "Only one box must be ticked or 'other disabilities' plus one of mobility disabilities"
end
end
end
def validate_shared_housing_rooms(record) def validate_shared_housing_rooms(record)
unless record.unittype_gn.nil? unless record.unittype_gn.nil?
if record.unittype_gn == "Bed-sit" && record.beds != 1 && record.beds.present? if record.unittype_gn == "Bed-sit" && record.beds != 1 && record.beds.present?

5
spec/features/form/saving_data_spec.rb

@ -17,7 +17,6 @@ RSpec.describe "Form Saving Data" do
FactoryBot.create( FactoryBot.create(
:case_log, :in_progress, :case_log, :in_progress,
housingneeds_a: "Yes", housingneeds_a: "Yes",
housingneeds_c: "Yes",
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation managing_organisation: user.organisation
) )
@ -93,9 +92,5 @@ RSpec.describe "Form Saving Data" do
"case-log-accessibility-requirements-housingneeds-b-field", "case-log-accessibility-requirements-housingneeds-b-field",
visible: false, visible: false,
) )
expect(page).to have_checked_field(
"case-log-accessibility-requirements-housingneeds-c-field",
visible: false,
)
end end
end end

55
spec/models/case_log_spec.rb

@ -826,6 +826,61 @@ RSpec.describe Form, type: :model do
}.not_to raise_error }.not_to raise_error
end end
end end
context "For accessibility requirements" do
it "validates that only one option can be selected" do
expect {
CaseLog.create!(housingneeds_a: "Yes",
housingneeds_b: "Yes",
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "validates that only one option a, b, or c can be selected in conjunction with f" do
expect {
CaseLog.create!(housingneeds_a: "Yes",
housingneeds_f: "Yes",
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to_not raise_error
expect {
CaseLog.create!(housingneeds_b: "Yes",
housingneeds_f: "Yes",
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to_not raise_error
expect {
CaseLog.create!(housingneeds_c: "Yes",
housingneeds_f: "Yes",
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to_not raise_error
expect {
CaseLog.create!(housingneeds_g: "Yes",
housingneeds_f: "Yes",
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(housingneeds_a: "Yes",
housingneeds_b: "Yes",
housingneeds_f: "Yes",
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
end end
describe "status" do describe "status" do

13
spec/requests/form_controller_spec.rb

@ -135,9 +135,7 @@ RSpec.describe FormController, type: :request do
case_log: { case_log: {
page: "accessibility_requirements", page: "accessibility_requirements",
accessibility_requirements: accessibility_requirements:
%w[ housingneeds_a %w[housingneeds_b],
housingneeds_b
housingneeds_c],
}, },
} }
end end
@ -156,16 +154,13 @@ RSpec.describe FormController, type: :request do
post "/logs/#{case_log.id}/form", params: case_log_form_params post "/logs/#{case_log.id}/form", params: case_log_form_params
case_log.reload case_log.reload
expect(case_log.housingneeds_a).to eq("Yes")
expect(case_log.housingneeds_b).to eq("Yes") expect(case_log.housingneeds_b).to eq("Yes")
expect(case_log.housingneeds_c).to eq("Yes")
end end
it "sets previously submitted items to false when resubmitted with new values" do it "sets previously submitted items to false when resubmitted with new values" do
post "/logs/#{case_log.id}/form", params: new_case_log_form_params post "/logs/#{case_log.id}/form", params: new_case_log_form_params
case_log.reload case_log.reload
expect(case_log.housingneeds_a).to eq("No")
expect(case_log.housingneeds_b).to eq("No") expect(case_log.housingneeds_b).to eq("No")
expect(case_log.housingneeds_c).to eq("Yes") expect(case_log.housingneeds_c).to eq("Yes")
end end
@ -179,8 +174,7 @@ RSpec.describe FormController, type: :request do
page: "accessibility_requirements", page: "accessibility_requirements",
accessibility_requirements: accessibility_requirements:
%w[ housingneeds_a %w[ housingneeds_a
housingneeds_b housingneeds_f],
housingneeds_c],
tenant_code: tenant_code, tenant_code: tenant_code,
}, },
} }
@ -213,8 +207,7 @@ RSpec.describe FormController, type: :request do
case_log.reload case_log.reload
expect(case_log.housingneeds_a).to eq("Yes") expect(case_log.housingneeds_a).to eq("Yes")
expect(case_log.housingneeds_b).to eq("Yes") expect(case_log.housingneeds_f).to eq("Yes")
expect(case_log.housingneeds_c).to eq("Yes")
expect(case_log.tenant_code).to eq(tenant_code) expect(case_log.tenant_code).to eq(tenant_code)
end end
end end

Loading…
Cancel
Save