Browse Source

CLDC-3228 Age validation update (#2197)

* feat: unrelated nil safe notifications tweak

* feat: update under 16 validations and copy

* feat: include person_num in error text

* feaT: update copy for relat

* feat: update tests
pull/2202/head v0.4.12
natdeanlewissoftwire 11 months ago committed by GitHub
parent
commit
7dcbfb1341
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/controllers/notifications_controller.rb
  2. 18
      app/models/validations/household_validations.rb
  3. 34
      app/models/validations/sales/household_validations.rb
  4. 12
      config/locales/en.yml
  5. 6
      spec/models/validations/household_validations_spec.rb
  6. 6
      spec/models/validations/sales/household_validations_spec.rb
  7. 2
      spec/services/merge/merge_organisations_service_spec.rb

2
app/controllers/notifications_controller.rb

@ -3,7 +3,7 @@ class NotificationsController < ApplicationController
if current_user.blank? if current_user.blank?
redirect_to root_path redirect_to root_path
else else
current_user.newest_active_unread_notification.mark_as_read! for: current_user current_user.newest_active_unread_notification.mark_as_read! for: current_user if current_user.newest_active_unread_notification.present?
redirect_back(fallback_location: root_path) redirect_back(fallback_location: root_path)
end end
end end

18
app/models/validations/household_validations.rb

@ -167,9 +167,9 @@ private
economic_status = record.public_send("ecstat#{person_num}") economic_status = record.public_send("ecstat#{person_num}")
return unless age && economic_status return unless age && economic_status
if age < 16 && !tenant_is_economic_child?(economic_status) if age < 16 && !economic_status_is_child_other_or_refused?(economic_status)
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:) record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_ecstat", person_num:)
end end
if tenant_is_economic_child?(economic_status) && age > 16 if tenant_is_economic_child?(economic_status) && age > 16
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_over_16", person_num:) record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_over_16", person_num:)
@ -182,9 +182,9 @@ private
relationship = record.public_send("relat#{person_num}") relationship = record.public_send("relat#{person_num}")
return unless age && relationship return unless age && relationship
if age < 16 && !tenant_is_child?(relationship) if age < 16 && !relationship_is_child_other_or_refused?(relationship)
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_under_16", person_num:) record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_under_16_lettings", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_relat", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_relat_lettings", person_num:)
end end
end end
@ -224,7 +224,15 @@ private
economic_status == 10 economic_status == 10
end end
def economic_status_is_child_other_or_refused?(economic_status)
[9, 0, 10].include?(economic_status)
end
def tenant_is_child?(relationship) def tenant_is_child?(relationship)
relationship == "C" relationship == "C"
end end
def relationship_is_child_other_or_refused?(relationship)
%w[C X R].include?(relationship)
end
end end

34
app/models/validations/sales/household_validations.rb

@ -37,9 +37,9 @@ private
relationship = record.public_send("relat#{person_num}") relationship = record.public_send("relat#{person_num}")
return unless age && relationship return unless age && relationship
if age < 16 && person_is_partner?(relationship) if age < 16 && !relationship_is_child_other_or_refused?(relationship)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.partner_under_16") record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_relat_sales", person_num:)
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.partner_under_16") record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_under_16_sales", person_num:)
elsif age >= 20 && person_is_child?(relationship) elsif age >= 20 && person_is_child?(relationship)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_over_20") record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_over_20")
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_over_20") record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_over_20")
@ -75,9 +75,9 @@ private
economic_status = record.public_send("ecstat#{person_num}") economic_status = record.public_send("ecstat#{person_num}")
return unless age && economic_status return unless age && economic_status
if age < 16 && !person_is_economic_child?(economic_status) if age < 16 && !economic_status_is_child_other_or_refused?(economic_status)
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:) record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_ecstat", person_num:)
end end
if person_is_economic_child?(economic_status) && age > 16 if person_is_economic_child?(economic_status) && age > 16
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_over_16", person_num:) record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_over_16", person_num:)
@ -98,18 +98,10 @@ private
end end
end end
def person_is_partner?(relationship)
relationship == "P"
end
def person_is_fulltime_student?(economic_status) def person_is_fulltime_student?(economic_status)
economic_status == 7 economic_status == 7
end end
def person_is_child?(relationship)
relationship == "C"
end
def person_is_economic_child?(economic_status) def person_is_economic_child?(economic_status)
economic_status == 9 economic_status == 9
end end
@ -117,4 +109,20 @@ private
def person_economic_status_refused?(economic_status) def person_economic_status_refused?(economic_status)
economic_status == 10 economic_status == 10
end end
def economic_status_is_child_other_or_refused?(economic_status)
[9, 0, 10].include?(economic_status)
end
def person_is_partner?(relationship)
relationship == "P"
end
def person_is_child?(relationship)
relationship == "C"
end
def relationship_is_child_other_or_refused?(relationship)
%w[C X R].include?(relationship)
end
end end

12
config/locales/en.yml

@ -450,8 +450,9 @@ en:
retired_male: "A male tenant who is retired must be 65 or over" retired_male: "A male tenant who is retired must be 65 or over"
retired_female: "A female tenant who is retired must be 60 or over" retired_female: "A female tenant who is retired must be 60 or over"
retired_over_70: "Answer cannot be over 70 as person %{person_num} has economic status that is not ‘retired’" retired_over_70: "Answer cannot be over 70 as person %{person_num} has economic status that is not ‘retired’"
child_under_16_relat: "Answer cannot be under 16 as person %{person_num} is not a child of the lead tenant" child_under_16_relat_lettings: "Answer cannot be under 16 as person %{person_num}'s relationship to the lead tenant is ‘partner’"
child_under_16: "Answer cannot be under 16 as person’s %{person_num} working situation is not ‘child under 16’" child_under_16_relat_sales: "Answer cannot be under 16 as person %{person_num}'s relationship to buyer 1 is ‘partner’"
child_under_16_ecstat: "Answer cannot be under 16 as person %{person_num}’s working situation is not ‘child under 16’, ‘other’ or ‘prefers not to say’"
child_over_16: "Answer cannot be over 16 as person’s %{person_num} working situation is ‘child under 16‘" child_over_16: "Answer cannot be over 16 as person’s %{person_num} working situation is ‘child under 16‘"
child_over_20: "Answer cannot be 20 or over as the relationship is ‘child’" child_over_20: "Answer cannot be 20 or over as the relationship is ‘child’"
child_12_years_younger: "A child must be at least 12 years younger than their parent" child_12_years_younger: "A child must be at least 12 years younger than their parent"
@ -460,12 +461,11 @@ en:
cannot_be_16_19: cannot_be_16_19:
child_not_student: "Person cannot be aged 16-19 if they have relationship ‘child’ but are not a student" child_not_student: "Person cannot be aged 16-19 if they have relationship ‘child’ but are not a student"
must_be_16_19: "Person must be aged 16-19 if they are a student and have relationship ‘child’" must_be_16_19: "Person must be aged 16-19 if they are a student and have relationship ‘child’"
partner_under_16: "Cannot be under 16 if the relationship is partner"
lead: lead:
over_25: "The lead tenant must be under 26 as you told us their housing situation immediately before this letting was a children’s home or foster care" over_25: "The lead tenant must be under 26 as you told us their housing situation immediately before this letting was a children’s home or foster care"
ecstat: ecstat:
retired_over_70: "Person %{person_num} must be retired if over 70" retired_over_70: "Person %{person_num} must be retired if over 70"
child_under_16: "Person %{person_num}’s working situation must be ‘child under 16’ as you told us they’re under 16" child_under_16: "Person %{person_num}’s working situation must be ‘child under 16’, ‘other’ or ‘prefers not to say’ as you told us they’re under 16"
child_over_16: "Answer cannot be ‘child under 16’ as you told us the person %{person_num} is older than 16" child_over_16: "Answer cannot be ‘child under 16’ as you told us the person %{person_num} is older than 16"
not_student_16_19: "Person’s %{person_num} working situation must be full-time student or prefers not to say as you told us they’re between 16 and 19." not_student_16_19: "Person’s %{person_num} working situation must be full-time student or prefers not to say as you told us they’re between 16 and 19."
student_16_19: student_16_19:
@ -475,8 +475,8 @@ en:
retired_male: "Answer cannot be ‘retired’ as the male tenant is under 65" retired_male: "Answer cannot be ‘retired’ as the male tenant is under 65"
retired_female: "Answer cannot be ‘retired’ as the female tenant is under 60" retired_female: "Answer cannot be ‘retired’ as the female tenant is under 60"
relat: relat:
partner_under_16: "Answer cannot be ‘partner’ if the person's age is under 16" child_under_16_sales: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16"
child_under_16: "Person’s relationship to tenant 1 must be ‘child’ as you told us they’re under 16" child_under_16_lettings: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16"
child_over_20: "Answer cannot be ‘child’ if the person's age is 20 or over" child_over_20: "Answer cannot be ‘child’ if the person's age is 20 or over"
one_partner: "Number of partners cannot be greater than 1" one_partner: "Number of partners cannot be greater than 1"
not_student_16_19: "Answer cannot be ‘child’ as you told us the person %{person_num} is between 16 and 19 and is not a full-time student" not_student_16_19: "Answer cannot be ‘child’ as you told us the person %{person_num} is between 16 and 19 and is not a full-time student"

6
spec/models/validations/household_validations_spec.rb

@ -255,9 +255,9 @@ RSpec.describe Validations::HouseholdValidations do
record.relat2 = "P" record.relat2 = "P"
household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record)
expect(record.errors["relat2"]) expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.child_under_16", person_num: 2)) .to include(match I18n.t("validations.household.relat.child_under_16_lettings", person_num: 2))
expect(record.errors["age2"]) expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.child_under_16_relat", person_num: 2)) .to include(match I18n.t("validations.household.age.child_under_16_relat_lettings", person_num: 2))
end end
it "expects that person is a child of the tenant" do it "expects that person is a child of the tenant" do
@ -275,7 +275,7 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["ecstat2"]) expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.child_under_16", person_num: 2)) .to include(match I18n.t("validations.household.ecstat.child_under_16", person_num: 2))
expect(record.errors["age2"]) expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.child_under_16", person_num: 2)) .to include(match I18n.t("validations.household.age.child_under_16_ecstat", person_num: 2))
end end
it "expects that person's economic status is Child" do it "expects that person's economic status is Child" do

6
spec/models/validations/sales/household_validations_spec.rb

@ -40,9 +40,9 @@ RSpec.describe Validations::Sales::HouseholdValidations do
record.relat2 = "P" record.relat2 = "P"
household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record)
expect(record.errors["relat2"]) expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.partner_under_16")) .to include(match I18n.t("validations.household.relat.child_under_16_sales", person_num: 2))
expect(record.errors["age2"]) expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.partner_under_16")) .to include(match I18n.t("validations.household.age.child_under_16_relat_sales", person_num: 2))
end end
it "validates that person's economic status must be Child" do it "validates that person's economic status must be Child" do
@ -52,7 +52,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
expect(record.errors["ecstat2"]) expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.child_under_16", person_num: 2)) .to include(match I18n.t("validations.household.ecstat.child_under_16", person_num: 2))
expect(record.errors["age2"]) expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.child_under_16", person_num: 2)) .to include(match I18n.t("validations.household.age.child_under_16_ecstat", person_num: 2))
end end
it "expects that person's economic status is Child" do it "expects that person's economic status is Child" do

2
spec/services/merge/merge_organisations_service_spec.rb

@ -752,7 +752,7 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbing_organisation.owned_schemes.first.locations.map(&:postcode)).to match_array([location, deactivated_location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode)) expect(absorbing_organisation.owned_schemes.first.locations.map(&:postcode)).to match_array([location, deactivated_location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode))
expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday) expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday)
expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday) expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday)
expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_future_startdate.postcode).startdate).to eq(Time.zone.today + 2.months) expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_future_startdate.postcode).startdate).to eq(Time.zone.local(2024, 4, 1))
absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name) absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name)
absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode) absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode)
expect(absorbed_active_scheme.service_name).to eq(scheme.service_name) expect(absorbed_active_scheme.service_name).to eq(scheme.service_name)

Loading…
Cancel
Save