Browse Source

CLDC-3405-update-retirement-age-validation (#2384)

* update retirement soft validation pages and copy in en.yml to reflect changes in english retirement age

* update soft validation tests to display interruption screens under the correct conditions given changes to state retirement age
reduction of variation in retirement age means lots of code related to determining the retirement age given an individuals gender can also be removed
testing updated
pull/2393/head
Arthur Campbell 8 months ago committed by GitHub
parent
commit
44a0b1acb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      app/models/form/lettings/pages/lead_tenant_over_retirement_value_check.rb
  2. 21
      app/models/form/lettings/pages/person_over_retirement_value_check.rb
  3. 8
      app/models/lettings_log.rb
  4. 4
      app/models/log.rb
  5. 8
      app/models/sales_log.rb
  6. 11
      app/models/validations/soft_validations.rb
  7. 6
      config/locales/en.yml
  8. 38
      spec/models/form/lettings/pages/person_over_retirement_value_check_spec.rb
  9. 50
      spec/models/lettings_log_spec.rb
  10. 78
      spec/models/validations/soft_validations_spec.rb

17
app/models/form/lettings/pages/lead_tenant_over_retirement_value_check.rb

@ -4,24 +4,9 @@ class Form::Lettings::Pages::LeadTenantOverRetirementValueCheck < ::Form::Page
@depends_on = [{ "person_1_not_retired_over_soft_max_age?" => true }] @depends_on = [{ "person_1_not_retired_over_soft_max_age?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.retirement.max.title", "translation" => "soft_validations.retirement.max.title",
"arguments" => [
{
"key" => "retirement_age_for_person_1",
"label" => false,
"i18n_template" => "age",
},
],
} }
@informative_text = { @informative_text = {
"translation" => "soft_validations.retirement.max.hint_text", "translation" => "soft_validations.retirement.max.hint_text",
"arguments" => [
{ "key" => "plural_gender_for_person_1", "label" => false, "i18n_template" => "gender" },
{
"key" => "retirement_age_for_person_1",
"label" => false,
"i18n_template" => "age",
},
],
} }
end end
@ -30,6 +15,6 @@ class Form::Lettings::Pages::LeadTenantOverRetirementValueCheck < ::Form::Page
end end
def interruption_screen_question_ids def interruption_screen_question_ids
%w[ecstat1 sex1 age1] %w[ecstat1 age1]
end end
end end

21
app/models/form/lettings/pages/person_over_retirement_value_check.rb

@ -4,28 +4,9 @@ class Form::Lettings::Pages::PersonOverRetirementValueCheck < ::Form::Page
@depends_on = [{ "person_#{person_index}_not_retired_over_soft_max_age?" => true }] @depends_on = [{ "person_#{person_index}_not_retired_over_soft_max_age?" => true }]
@title_text = { @title_text = {
"translation" => "soft_validations.retirement.max.title", "translation" => "soft_validations.retirement.max.title",
"arguments" => [
{
"key" => "retirement_age_for_person_#{person_index}",
"label" => false,
"i18n_template" => "age",
},
],
} }
@informative_text = { @informative_text = {
"translation" => "soft_validations.retirement.max.hint_text", "translation" => "soft_validations.retirement.max.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_#{person_index}",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_#{person_index}",
"label" => false,
"i18n_template" => "age",
},
],
} }
@person_index = person_index @person_index = person_index
end end
@ -35,6 +16,6 @@ class Form::Lettings::Pages::PersonOverRetirementValueCheck < ::Form::Page
end end
def interruption_screen_question_ids def interruption_screen_question_ids
["ecstat#{@person_index}", "sex#{@person_index}", "age#{@person_index}"] ["ecstat#{@person_index}", "age#{@person_index}"]
end end
end end

8
app/models/lettings_log.rb

@ -138,7 +138,6 @@ class LettingsLog < Log
HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze
NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52, 10 => 53 }.freeze NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52, 10 => 53 }.freeze
SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze
RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze
DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id tenancycode startdate age1_known age1 sex1 ecstat1 tcharge household_charge chcharge].freeze DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id tenancycode startdate age1_known age1 sex1 ecstat1 tcharge household_charge chcharge].freeze
RENT_TYPE = { RENT_TYPE = {
social_rent: 0, social_rent: 0,
@ -555,13 +554,6 @@ class LettingsLog < Log
OPTIONAL_FIELDS + dynamically_not_required OPTIONAL_FIELDS + dynamically_not_required
end end
def retirement_age_for_person(person_num)
gender = public_send("sex#{person_num}".to_sym)
return unless gender
RETIREMENT_AGES[gender]
end
def age_unknown?(person_num) def age_unknown?(person_num)
return false unless person_num.is_a?(Integer) return false unless person_num.is_a?(Integer)

4
app/models/log.rb

@ -205,10 +205,6 @@ class Log < ApplicationRecord
end end
(1..8).each do |person_num| (1..8).each do |person_num|
define_method("retirement_age_for_person_#{person_num}") do
retirement_age_for_person(person_num)
end
define_method("plural_gender_for_person_#{person_num}") do define_method("plural_gender_for_person_#{person_num}") do
plural_gender_for_person(person_num) plural_gender_for_person(person_num)
end end

8
app/models/sales_log.rb

@ -85,7 +85,6 @@ class SalesLog < Log
} }
OPTIONAL_FIELDS = %w[purchid othtype buyers_organisations].freeze OPTIONAL_FIELDS = %w[purchid othtype buyers_organisations].freeze
RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze
DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id purchid saledate age1_known age1 sex1 ecstat1 postcode_full].freeze DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id purchid saledate age1_known age1 sex1 ecstat1 postcode_full].freeze
def lettings? def lettings?
@ -368,13 +367,6 @@ class SalesLog < Log
update!(created_by: nil) update!(created_by: nil)
end end
def retirement_age_for_person(person_num)
gender = public_send("sex#{person_num}".to_sym)
return unless gender
RETIREMENT_AGES[gender]
end
def joint_purchase? def joint_purchase?
jointpur == 1 jointpur == 1
end end

11
app/models/validations/soft_validations.rb

@ -239,18 +239,17 @@ private
economic_status = public_send("ecstat#{person_num}") economic_status = public_send("ecstat#{person_num}")
return unless age && economic_status return unless age && economic_status
tenant_is_retired?(economic_status) && age < 60 tenant_is_retired?(economic_status) && age < 66
end end
def not_retired_over_soft_max_age?(person_num) def not_retired_over_soft_max_age?(person_num)
age = public_send("age#{person_num}") age = public_send("age#{person_num}")
economic_status = public_send("ecstat#{person_num}") economic_status = public_send("ecstat#{person_num}")
gender = public_send("sex#{person_num}") return unless age && economic_status
tenant_retired_or_prefers_not_say = tenant_is_retired?(economic_status) || tenant_prefers_not_to_say?(economic_status)
return unless age && economic_status && gender return false if tenant_prefers_not_to_say?(economic_status)
%w[M X].include?(gender) && !tenant_retired_or_prefers_not_say && age > retirement_age_for_person(person_num) || !tenant_is_retired?(economic_status) && age > 66
gender == "F" && !tenant_retired_or_prefers_not_say && age > 60
end end
def partner_under_16?(person_num) def partner_under_16?(person_num)

6
config/locales/en.yml

@ -689,10 +689,10 @@ Make sure these answers are correct."
retirement: retirement:
min: min:
title: "You told us this person is aged %{age} years and retired." title: "You told us this person is aged %{age} years and retired."
hint_text: "The minimum expected retirement age for %{gender} in England is %{age}." hint_text: "The minimum expected retirement age in England is 66."
max: max:
title: "You told us this person is %{age} or over and not retired" title: "You told us this person is over 66 and not retired"
hint_text: "The minimum expected retirement age for %{gender} in England is %{age}." hint_text: "The minimum expected retirement age in England is 66."
extra_borrowing: extra_borrowing:
title_text: "You told us that the mortgage and deposit total is %{mortgage_and_deposit_total}" title_text: "You told us that the mortgage and deposit total is %{mortgage_and_deposit_total}"
hint_text: "This is higher than the purchase price minus the discount." hint_text: "This is higher than the purchase price minus the discount."

38
spec/models/form/lettings/pages/person_over_retirement_value_check_spec.rb

@ -33,31 +33,12 @@ RSpec.describe Form::Lettings::Pages::PersonOverRetirementValueCheck, type: :mod
it "has the correct title_text" do it "has the correct title_text" do
expect(page.title_text).to eq({ expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.max.title", "translation" => "soft_validations.retirement.max.title",
"arguments" => [
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
}) })
end end
it "has the correct informative_text" do it "has the correct informative_text" do
expect(page.informative_text).to eq({ expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.max.hint_text", "translation" => "soft_validations.retirement.max.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_2",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
}) })
end end
end end
@ -74,31 +55,12 @@ RSpec.describe Form::Lettings::Pages::PersonOverRetirementValueCheck, type: :mod
it "has the correct title_text" do it "has the correct title_text" do
expect(page.title_text).to eq({ expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.max.title", "translation" => "soft_validations.retirement.max.title",
"arguments" => [
{
"key" => "retirement_age_for_person_3",
"label" => false,
"i18n_template" => "age",
},
],
}) })
end end
it "has the correct informative_text" do it "has the correct informative_text" do
expect(page.informative_text).to eq({ expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.max.hint_text", "translation" => "soft_validations.retirement.max.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_3",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_3",
"label" => false,
"i18n_template" => "age",
},
],
}) })
end end
end end

50
spec/models/lettings_log_spec.rb

@ -3382,55 +3382,6 @@ RSpec.describe LettingsLog do
end end
end end
describe "#retirement_age_for_person" do
context "when a person gender is Male" do
let(:lettings_log) { build(:lettings_log, sex1: "M") }
it "returns the expected retirement age" do
expect(lettings_log.retirement_age_for_person_1).to eq(67)
end
it "returns the expected plural" do
expect(lettings_log.plural_gender_for_person_1).to eq("male and non-binary people")
end
end
context "when a person gender is Female" do
let(:lettings_log) { build(:lettings_log, sex2: "F") }
it "returns the expected retirement age" do
expect(lettings_log.retirement_age_for_person_2).to eq(60)
end
it "returns the expected plural" do
expect(lettings_log.plural_gender_for_person_2).to eq("females")
end
end
context "when a person gender is Non-Binary" do
let(:lettings_log) { build(:lettings_log, sex3: "X") }
it "returns the expected retirement age" do
expect(lettings_log.retirement_age_for_person_3).to eq(67)
end
it "returns the expected plural" do
expect(lettings_log.plural_gender_for_person_3).to eq("male and non-binary people")
end
end
context "when the person gender is not set" do
let(:lettings_log) { build(:lettings_log) }
it "returns nil" do
expect(lettings_log.retirement_age_for_person_3).to be_nil
end
it "returns the expected plural" do
expect(lettings_log.plural_gender_for_person_3).to be_nil
end
end
context "when a postcode contains unicode characters" do context "when a postcode contains unicode characters" do
let(:lettings_log) { build(:lettings_log, postcode_full: "SR81LS\u00A0") } let(:lettings_log) { build(:lettings_log, postcode_full: "SR81LS\u00A0") }
@ -3438,7 +3389,6 @@ RSpec.describe LettingsLog do
expect { lettings_log.save! }.to raise_error(ActiveRecord::RecordInvalid, /Enter a postcode in the correct format/) expect { lettings_log.save! }.to raise_error(ActiveRecord::RecordInvalid, /Enter a postcode in the correct format/)
end end
end end
end
describe "#beds_for_la_rent_range" do describe "#beds_for_la_rent_range" do
context "when beds nil" do context "when beds nil" do

78
spec/models/validations/soft_validations_spec.rb

@ -83,62 +83,78 @@ RSpec.describe Validations::SoftValidations do
end end
describe "retirement soft validations" do describe "retirement soft validations" do
context "when the tenant is retired but under the expected retirement age" do before do
it "shows the interruption screen" do record.update!(age1:, ecstat1:)
record.update!(age1: 43, ecstat1: 5) end
expect(record.person_1_retired_under_soft_min_age?).to be true
context "when the tenant is under the expected retirement age" do
let(:age1) { 60 }
context "and the tenant's economic status is nil" do
let(:ecstat1) { nil }
it "does not show the interruption screen" do
expect(record).not_to be_person_1_retired_under_soft_min_age
end end
end end
context "when the tenant is not retired but over the expected retirement age" do context "and the tenant is retired" do
context "when the tenant is female" do let(:ecstat1) { 5 }
it "shows the interruption screen" do
record.update!(age1: 85, sex1: "F", ecstat1: 3) it "does show the interruption screen" do
expect(record.person_1_not_retired_over_soft_max_age?).to be true expect(record).to be_person_1_retired_under_soft_min_age
end end
end end
context "when the tenant is male" do context "and the tenant is not retired" do
it "shows the interruption screen" do let(:ecstat1) { 3 }
record.update!(age1: 85, sex1: "M", ecstat1: 3)
expect(record.person_1_not_retired_over_soft_max_age?).to be true it "does not show the interruption screen" do
expect(record).not_to be_person_1_retired_under_soft_min_age
end end
end end
context "when the tenant is non-binary" do context "and the tenant prefers not to say" do
it "shows the interruption screen" do let(:ecstat1) { 10 }
record.update!(age1: 85, sex1: "X", ecstat1: 3)
expect(record.person_1_not_retired_over_soft_max_age?).to be true it "does not show the interruption screen" do
expect(record).not_to be_person_1_retired_under_soft_min_age
end end
end end
end end
context "when the tenant prefers not to say what their economic status is but is under the expected retirement age" do context "when the tenant is over the expected retirement age" do
let(:age1) { 70 }
context "and the tenant's economic status is nil" do
let(:ecstat1) { nil }
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.update!(age1: 43, ecstat1: 10) expect(record).not_to be_person_1_not_retired_over_soft_max_age
expect(record.person_1_retired_under_soft_min_age?).to be false
end end
end end
context "when the tenant prefers not to say what their economic status is but is over the expected retirement age" do context "and the tenant is retired" do
context "when the tenant is female" do let(:ecstat1) { 5 }
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.update!(age1: 85, sex1: "F", ecstat1: 10) expect(record).not_to be_person_1_not_retired_over_soft_max_age
expect(record.person_1_not_retired_over_soft_max_age?).to be false
end end
end end
context "when the tenant is male" do context "and the tenant is not retired" do
it "does not show the interruption screen" do let(:ecstat1) { 3 }
record.update!(age1: 85, sex1: "M", ecstat1: 10)
expect(record.person_1_not_retired_over_soft_max_age?).to be false it "does show the interruption screen" do
expect(record).to be_person_1_not_retired_over_soft_max_age
end end
end end
context "when the tenant is non-binary" do context "and the tenant prefers not to say" do
let(:ecstat1) { 10 }
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.update!(age1: 85, sex1: "X", ecstat1: 10) expect(record).not_to be_person_1_not_retired_over_soft_max_age
expect(record.person_1_not_retired_over_soft_max_age?).to be false
end end
end end
end end

Loading…
Cancel
Save