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. 4
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  3. 4
      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
# or 'validate_' to run on submit as well
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 }
record.errors.add :reasonable_preference_reason, I18n.t("validations.household.reasonable_preference_reason.reason_not_required")
end

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

@ -689,9 +689,6 @@ private
end
def validate_reasonable_preference_homeless
if field_69 == 1 && homeless == 1 && field_70 == 1
errors.add(:field_70, I18n.t("validations.household.reasonpref.not_homeless"))
else
reason_fields = %i[field_70 field_71 field_72 field_73 field_74]
if field_69 == 1 && reason_fields.all? { |field| attributes[field.to_s].blank? }
reason_fields.each do |field|
@ -699,7 +696,6 @@ private
end
end
end
end
def validate_condition_effects
illness_option_fields = %i[field_119 field_120 field_121 field_122 field_123 field_124 field_125 field_126 field_127 field_128]

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

@ -622,9 +622,6 @@ private
end
def validate_reasonable_preference_homeless
if field_110 == 1 && field_105 == 1 && field_111 == 1
errors.add(:field_111, I18n.t("validations.household.reasonpref.not_homeless"))
else
reason_fields = %i[field_111 field_112 field_113 field_114 field_115]
if field_110 == 1 && reason_fields.all? { |field| attributes[field.to_s].blank? }
reason_fields.each do |field|
@ -632,7 +629,6 @@ private
end
end
end
end
def validate_condition_effects
illness_option_fields = %i[field_98 field_92 field_95 field_90 field_91 field_93 field_94 field_97 field_96 field_99]

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"
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:
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"

30
spec/models/validations/household_validations_spec.rb

@ -12,36 +12,6 @@ RSpec.describe Validations::HouseholdValidations do
end
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
it "validates that no reason is needed" do
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
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
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
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
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