Browse Source

Remove homelessness validation (#1877)

pull/1884/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
3b53e3e696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/validations/household_validations.rb
  2. 12
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  3. 12
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  4. 2
      config/locales/en.yml
  5. 30
      spec/models/validations/household_validations_spec.rb
  6. 8
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb
  7. 8
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

4
app/models/validations/household_validations.rb

@ -4,10 +4,6 @@ module Validations::HouseholdValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save # Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well # or 'validate_' to run on submit as well
def validate_reasonable_preference(record) def validate_reasonable_preference(record)
if record.is_not_homeless? && record.rp_homeless == 1
record.errors.add :reasonable_preference_reason, I18n.t("validations.household.reasonpref.not_homeless")
record.errors.add :homeless, I18n.t("validations.household.homeless.reasonpref.not_homeless")
end
if !record.given_reasonable_preference? && [record.rp_homeless, record.rp_insan_unsat, record.rp_medwel, record.rp_hardship, record.rp_dontknow].any? { |a| a == 1 } if !record.given_reasonable_preference? && [record.rp_homeless, record.rp_insan_unsat, record.rp_medwel, record.rp_hardship, record.rp_dontknow].any? { |a| a == 1 }
record.errors.add :reasonable_preference_reason, I18n.t("validations.household.reasonable_preference_reason.reason_not_required") record.errors.add :reasonable_preference_reason, I18n.t("validations.household.reasonable_preference_reason.reason_not_required")
end end

12
app/services/bulk_upload/lettings/year2022/row_parser.rb

@ -689,14 +689,10 @@ private
end end
def validate_reasonable_preference_homeless def validate_reasonable_preference_homeless
if field_69 == 1 && homeless == 1 && field_70 == 1 reason_fields = %i[field_70 field_71 field_72 field_73 field_74]
errors.add(:field_70, I18n.t("validations.household.reasonpref.not_homeless")) if field_69 == 1 && reason_fields.all? { |field| attributes[field.to_s].blank? }
else reason_fields.each do |field|
reason_fields = %i[field_70 field_71 field_72 field_73 field_74] errors.add(field, I18n.t("validations.not_answered", question: "reason for reasonable preference"))
if field_69 == 1 && reason_fields.all? { |field| attributes[field.to_s].blank? }
reason_fields.each do |field|
errors.add(field, I18n.t("validations.not_answered", question: "reason for reasonable preference"))
end
end end
end end
end end

12
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -622,14 +622,10 @@ private
end end
def validate_reasonable_preference_homeless def validate_reasonable_preference_homeless
if field_110 == 1 && field_105 == 1 && field_111 == 1 reason_fields = %i[field_111 field_112 field_113 field_114 field_115]
errors.add(:field_111, I18n.t("validations.household.reasonpref.not_homeless")) if field_110 == 1 && reason_fields.all? { |field| attributes[field.to_s].blank? }
else reason_fields.each do |field|
reason_fields = %i[field_111 field_112 field_113 field_114 field_115] errors.add(field, I18n.t("validations.not_answered", question: "reason for reasonable preference"))
if field_110 == 1 && reason_fields.all? { |field| attributes[field.to_s].blank? }
reason_fields.each do |field|
errors.add(field, I18n.t("validations.not_answered", question: "reason for reasonable preference"))
end
end end
end end
end end

2
config/locales/en.yml

@ -441,8 +441,6 @@ en:
mortgage: "Mortgage value cannot be £0 if a mortgage was used for the purchase of this property" mortgage: "Mortgage value cannot be £0 if a mortgage was used for the purchase of this property"
household: household:
reasonpref:
not_homeless: "Answer cannot be ‘homeless or about to lose their home’ as the tenant was not homeless immediately prior to this letting"
reasonable_preference_reason: reasonable_preference_reason:
reason_required: "Enter a reason if you've answered 'yes' to reasonable preference" reason_required: "Enter a reason if you've answered 'yes' to reasonable preference"
reason_not_required: "Do not enter a reason if you've answered 'no' to reasonable preference" reason_not_required: "Do not enter a reason if you've answered 'no' to reasonable preference"

30
spec/models/validations/household_validations_spec.rb

@ -12,36 +12,6 @@ RSpec.describe Validations::HouseholdValidations do
end end
describe "reasonable preference validations" do describe "reasonable preference validations" do
context "when reasonable preference is homeless" do
context "when the tenant was not previously homeless" do
it "adds an error" do
record.homeless = 1
record.rp_homeless = 1
household_validator.validate_reasonable_preference(record)
expect(record.errors["reasonable_preference_reason"])
.to include(match I18n.t("validations.household.reasonpref.not_homeless"))
expect(record.errors["homeless"])
.to include(match I18n.t("validations.household.homeless.reasonpref.not_homeless"))
end
end
context "when reasonable preference is given" do
context "when the tenant was previously homeless" do
it "does not add an error" do
record.homeless = 1
record.reasonpref = 1
household_validator.validate_reasonable_preference(record)
expect(record.errors["reasonpref"]).to be_empty
expect(record.errors["homeless"]).to be_empty
record.homeless = 0
household_validator.validate_reasonable_preference(record)
expect(record.errors["reasonpref"]).to be_empty
expect(record.errors["homeless"]).to be_empty
end
end
end
end
context "when reasonable preference is not given" do context "when reasonable preference is not given" do
it "validates that no reason is needed" do it "validates that no reason is needed" do
record.reasonpref = 1 record.reasonpref = 1

8
spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

@ -711,14 +711,6 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
end end
describe "#field_68 - 74" do describe "#field_68 - 74" do
context "when not homeless but reasonable preference for homelessness" do
let(:attributes) { { bulk_upload:, field_68: "1", field_69: "1", field_70: "1" } }
it "is not permitted" do
expect(parser.errors[:field_70]).to be_present
end
end
context "when there is a reasonable preference but none is given" do context "when there is a reasonable preference but none is given" do
let(:attributes) { { bulk_upload:, field_69: "1", field_70: nil, field_71: nil, field_72: nil, field_73: nil, field_74: nil } } let(:attributes) { { bulk_upload:, field_69: "1", field_70: nil, field_71: nil, field_72: nil, field_73: nil, field_74: nil } }

8
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -803,14 +803,6 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
describe "#field_105, field_110 - 15" do describe "#field_105, field_110 - 15" do
context "when not homeless but reasonable preference for homelessness" do
let(:attributes) { { bulk_upload:, field_105: "1", field_110: "1", field_111: "1" } }
it "is not permitted" do
expect(parser.errors[:field_111]).to be_present
end
end
context "when there is a reasonable preference but none is given" do context "when there is a reasonable preference but none is given" do
let(:attributes) { { bulk_upload:, field_110: "1", field_111: nil, field_112: nil, field_113: nil, field_114: nil, field_115: nil } } let(:attributes) { { bulk_upload:, field_110: "1", field_111: nil, field_112: nil, field_113: nil, field_114: nil, field_115: nil } }

Loading…
Cancel
Save