Browse Source

CLDC-1698 Simplify tenancy length range error message

pull/975/head
David May-Miller 3 years ago
parent
commit
68fdf49f84
  1. 24
      app/models/validations/tenancy_validations.rb
  2. 4
      config/locales/en.yml
  3. 8
      spec/models/validations/tenancy_validations_spec.rb

24
app/models/validations/tenancy_validations.rb

@ -16,8 +16,6 @@ module Validations::TenancyValidations
error: I18n.t( error: I18n.t(
"validations.tenancy.length.shorthold", "validations.tenancy.length.shorthold",
min_tenancy_length: min_tenancy_length(record), min_tenancy_length: min_tenancy_length(record),
rent_type: rent_type_mapping(record)[record.rent_type],
needs_type: needs_type_mapping[record.needstype],
), ),
}, },
{ {
@ -25,8 +23,6 @@ module Validations::TenancyValidations
error: I18n.t( error: I18n.t(
"validations.tenancy.length.secure", "validations.tenancy.length.secure",
min_tenancy_length: min_tenancy_length(record), min_tenancy_length: min_tenancy_length(record),
rent_type: rent_type_mapping(record)[record.rent_type],
needs_type: needs_type_mapping[record.needstype],
), ),
}, },
] ]
@ -53,24 +49,6 @@ module Validations::TenancyValidations
end end
def min_tenancy_length(record) def min_tenancy_length(record)
record.needstype == 2 || record.rent_type.in?([3, 5]) ? 1 : 2 record.needstype == 2 || record.renttype == 3 ? 1 : 2
end
def rent_type_mapping(record)
{
1 => "Affordable Rent",
2 => "London Affordable Rent",
4 => "London Living Rent",
3 => "Rent to Buy",
0 => "Social Rent",
5 => record.irproduct,
}
end
def needs_type_mapping
{
1 => "General needs",
2 => "Supported housing",
}
end end
end end

4
config/locales/en.yml

@ -301,8 +301,8 @@ en:
tenancy: tenancy:
length: length:
fixed_term_not_required: "You must only answer the length of the tenancy if it's fixed-term" fixed_term_not_required: "You must only answer the length of the tenancy if it's fixed-term"
shorthold: "Enter a tenancy length between %{min_tenancy_length} and 99 years for a %{needs_type} %{rent_type} Fixed Term – Assured Shorthold Tenancy (AST)" shorthold: "Enter a tenancy length between %{min_tenancy_length} and 99 years for a tenancy of this type"
secure: "Enter a tenancy length between %{min_tenancy_length} and 99 years (or don't specify the length) for a %{needs_type} %{rent_type} Secure (including flexible) tenancy" secure: "Enter a tenancy length between %{min_tenancy_length} and 99 years (or don't specify the length) for a tenancy of this type"
internal_transfer: "Answer must be secure tenancy as this tenancy is an internal transfer" internal_transfer: "Answer must be secure tenancy as this tenancy is an internal transfer"
cannot_be_internal_transfer: "Answer cannot be internal transfer as this is not a secure tenancy" cannot_be_internal_transfer: "Answer cannot be internal transfer as this is not a secure tenancy"
not_joint: "This cannot be a joint tenancy as you've told us there's only one person in the household" not_joint: "This cannot be a joint tenancy as you've told us there's only one person in the household"

8
spec/models/validations/tenancy_validations_spec.rb

@ -25,8 +25,6 @@ RSpec.describe Validations::TenancyValidations do
I18n.t( I18n.t(
"validations.tenancy.length.shorthold", "validations.tenancy.length.shorthold",
min_tenancy_length: 2, min_tenancy_length: 2,
needs_type: "General needs",
rent_type: "Affordable Rent",
) )
end end
@ -75,8 +73,6 @@ RSpec.describe Validations::TenancyValidations do
I18n.t( I18n.t(
"validations.tenancy.length.secure", "validations.tenancy.length.secure",
min_tenancy_length: 2, min_tenancy_length: 2,
needs_type: "General needs",
rent_type: "Affordable Rent",
) )
end end
@ -128,8 +124,6 @@ RSpec.describe Validations::TenancyValidations do
I18n.t( I18n.t(
"validations.tenancy.length.secure", "validations.tenancy.length.secure",
min_tenancy_length: 2, min_tenancy_length: 2,
needs_type: "General needs",
rent_type: "Affordable Rent",
) )
end end
@ -177,8 +171,6 @@ RSpec.describe Validations::TenancyValidations do
I18n.t( I18n.t(
"validations.tenancy.length.secure", "validations.tenancy.length.secure",
min_tenancy_length: 2, min_tenancy_length: 2,
needs_type: "General needs",
rent_type: "Affordable Rent",
) )
end end

Loading…
Cancel
Save