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. 58
      spec/models/lettings_log_spec.rb
  10. 82
      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 }]
@title_text = {
"translation" => "soft_validations.retirement.max.title",
"arguments" => [
{
"key" => "retirement_age_for_person_1",
"label" => false,
"i18n_template" => "age",
},
],
}
@informative_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
@ -30,6 +15,6 @@ class Form::Lettings::Pages::LeadTenantOverRetirementValueCheck < ::Form::Page
end
def interruption_screen_question_ids
%w[ecstat1 sex1 age1]
%w[ecstat1 age1]
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 }]
@title_text = {
"translation" => "soft_validations.retirement.max.title",
"arguments" => [
{
"key" => "retirement_age_for_person_#{person_index}",
"label" => false,
"i18n_template" => "age",
},
],
}
@informative_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
end
@ -35,6 +16,6 @@ class Form::Lettings::Pages::PersonOverRetirementValueCheck < ::Form::Page
end
def interruption_screen_question_ids
["ecstat#{@person_index}", "sex#{@person_index}", "age#{@person_index}"]
["ecstat#{@person_index}", "age#{@person_index}"]
end
end

8
app/models/lettings_log.rb

@ -138,7 +138,6 @@ class LettingsLog < Log
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
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
RENT_TYPE = {
social_rent: 0,
@ -555,13 +554,6 @@ class LettingsLog < Log
OPTIONAL_FIELDS + dynamically_not_required
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)
return false unless person_num.is_a?(Integer)

4
app/models/log.rb

@ -205,10 +205,6 @@ class Log < ApplicationRecord
end
(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
plural_gender_for_person(person_num)
end

8
app/models/sales_log.rb

@ -85,7 +85,6 @@ class SalesLog < Log
}
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
def lettings?
@ -368,13 +367,6 @@ class SalesLog < Log
update!(created_by: nil)
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?
jointpur == 1
end

11
app/models/validations/soft_validations.rb

@ -239,18 +239,17 @@ private
economic_status = public_send("ecstat#{person_num}")
return unless age && economic_status
tenant_is_retired?(economic_status) && age < 60
tenant_is_retired?(economic_status) && age < 66
end
def not_retired_over_soft_max_age?(person_num)
age = public_send("age#{person_num}")
economic_status = public_send("ecstat#{person_num}")
gender = public_send("sex#{person_num}")
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 unless age && economic_status
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) ||
gender == "F" && !tenant_retired_or_prefers_not_say && age > 60
!tenant_is_retired?(economic_status) && age > 66
end
def partner_under_16?(person_num)

6
config/locales/en.yml

@ -689,10 +689,10 @@ Make sure these answers are correct."
retirement:
min:
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:
title: "You told us this person is %{age} or over and not retired"
hint_text: "The minimum expected retirement age for %{gender} in England is %{age}."
title: "You told us this person is over 66 and not retired"
hint_text: "The minimum expected retirement age in England is 66."
extra_borrowing:
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."

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

58
spec/models/lettings_log_spec.rb

@ -3382,61 +3382,11 @@ RSpec.describe LettingsLog do
end
end
describe "#retirement_age_for_person" do
context "when a person gender is Male" do
let(:lettings_log) { build(:lettings_log, sex1: "M") }
context "when a postcode contains unicode characters" do
let(:lettings_log) { build(:lettings_log, postcode_full: "SR81LS\u00A0") }
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
let(:lettings_log) { build(:lettings_log, postcode_full: "SR81LS\u00A0") }
it "triggers a validation error" do
expect { lettings_log.save! }.to raise_error(ActiveRecord::RecordInvalid, /Enter a postcode in the correct format/)
end
it "triggers a validation error" do
expect { lettings_log.save! }.to raise_error(ActiveRecord::RecordInvalid, /Enter a postcode in the correct format/)
end
end

82
spec/models/validations/soft_validations_spec.rb

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

Loading…
Cancel
Save