Browse Source

Household situation fixes (#332)

* content changes and prevloc validation

* add la validation to the property information section

* Fix the tests
pull/333/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
3f9cd65365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/models/validations/household_validations.rb
  2. 4
      app/models/validations/property_validations.rb
  3. 2
      config/forms/2021_2022.json
  4. 2
      config/locales/en.yml
  5. 3
      spec/features/form/accessible_autocomplete_spec.rb
  6. 9
      spec/features/form/check_answers_page_spec.rb
  7. 11
      spec/models/validations/household_validations_spec.rb
  8. 9
      spec/models/validations/property_validations_spec.rb

6
app/models/validations/household_validations.rb

@ -90,6 +90,12 @@ module Validations::HouseholdValidations
end
end
def validate_prevloc(record)
if record.previous_la_known == "Yes" && record.prevloc.blank?
record.errors.add :prevloc, I18n.t("validations.household.previous_la_known")
end
end
private
def women_of_child_bearing_age_in_household(record)

4
app/models/validations/property_validations.rb

@ -27,6 +27,10 @@ module Validations::PropertyValidations
if record.la.present? && !LONDON_BOROUGHS.include?(record.la) && (record.rent_type == "London Affordable rent" || record.rent_type == "London living rent")
record.errors.add :la, I18n.t("validations.property.la.london_rent")
end
if record.la_known == "Yes" && record.la.blank?
record.errors.add :la, I18n.t("validations.property.la.la_known")
end
end
FIRST_LET_VACANCY_REASONS = ["First let of new-build property",

2
config/forms/2021_2022.json

@ -2687,7 +2687,7 @@
"description": "",
"questions": {
"previous_postcode_known": {
"header": "Do you know the property’s postcode?",
"header": "Do you know the postcode of the household’s last settled accommodation?",
"hint_text": "This is also known as the household’s ’last settled home’.",
"type": "radio",
"answer_options": {

2
config/locales/en.yml

@ -55,6 +55,7 @@ en:
relet_number: "Property number of times relet must be between 0 and 20"
la:
london_rent: "Local authority has to be in London"
la_known: "Enter a local authority"
rsnvac:
first_let_not_social: "Reason for vacancy cannot be first let if unit has been previously let as social housing"
first_let_social: "Reason for vacancy must be first let if unit has been previously let as social housing"
@ -126,6 +127,7 @@ en:
internal_transfer: "Answer cannot be other homelessness as you already told us this tenancy was an internal transfer"
reasonpref:
not_homeless: "Can not be No if household was given reasonable preference"
previous_la_known: "Enter a local authority"
tenancy:

3
spec/features/form/accessible_autocomplete_spec.rb

@ -9,6 +9,7 @@ RSpec.describe "Accessible Automcomplete" do
:case_log,
:in_progress,
la_known: "Yes",
la: "Westminster",
is_la_inferred: false,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
@ -39,7 +40,7 @@ RSpec.describe "Accessible Automcomplete" do
end
it "has the correct option selected if one has been saved" do
case_log.update!(postcode_known: "No", la: "Oxford")
case_log.update!(postcode_known: "No", la_known: "Yes", la: "Oxford")
visit("/logs/#{case_log.id}/accessible-select")
expect(page).to have_select("case-log-la-field", selected: %w[Oxford])
end

9
spec/features/form/check_answers_page_spec.rb

@ -18,6 +18,7 @@ RSpec.describe "Form Check Answers Page" do
FactoryBot.create(
:case_log,
la_known: "Yes",
la: "Westminster",
is_la_inferred: false,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
@ -86,14 +87,14 @@ RSpec.describe "Form Check Answers Page" do
it "updates the change/answer link when answers get updated" do
visit("/logs/#{empty_case_log.id}/household-needs/check-answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 5
assert_selector "a", text: "Change", count: 0
assert_selector "a", text: /Answer (?!the missing questions)/, count: 4
assert_selector "a", text: "Change", count: 1
visit("/logs/#{empty_case_log.id}/accessibility-requirements")
check("case-log-accessibility-requirements-housingneeds-c-field")
click_button("Save and continue")
visit("/logs/#{empty_case_log.id}/household-needs/check-answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 4
assert_selector "a", text: "Change", count: 1
assert_selector "a", text: /Answer (?!the missing questions)/, count: 3
assert_selector "a", text: "Change", count: 2
expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/accessibility-requirements")
end

11
spec/models/validations/household_validations_spec.rb

@ -536,4 +536,15 @@ RSpec.describe Validations::HouseholdValidations do
end
end
end
describe "la validations" do
context "when previous la is known" do
it "prevloc has to be provided" do
record.previous_la_known = "Yes"
household_validator.validate_prevloc(record)
expect(record.errors["prevloc"])
.to include(match I18n.t("validations.household.previous_la_known"))
end
end
end
end

9
spec/models/validations/property_validations_spec.rb

@ -157,6 +157,15 @@ RSpec.describe Validations::PropertyValidations do
expect(record.errors["la"]).to be_empty
end
end
context "when previous la is known" do
it "la has to be provided" do
record.la_known = "Yes"
property_validator.validate_la(record)
expect(record.errors["la"])
.to include(match I18n.t("validations.property.la.la_known"))
end
end
end
describe "#validate_unitletas" do

Loading…
Cancel
Save