Browse Source

Update error messages to reflect when length is allowed to be blank correctly

pull/2295/head
Rachael Booth 2 years ago
parent
commit
dda2a9de81
  1. 8
      app/models/validations/tenancy_validations.rb
  2. 4
      config/locales/en.yml
  3. 6
      spec/models/validations/tenancy_validations_spec.rb

8
app/models/validations/tenancy_validations.rb

@ -12,7 +12,7 @@ module Validations::TenancyValidations
min_tenancy_length = 1 min_tenancy_length = 1
return if record.tenancylength.to_i.between?(min_tenancy_length, 99) return if record.tenancylength.to_i.between?(min_tenancy_length, 99)
message = record.is_assured_shorthold_tenancy? ? I18n.t("validations.tenancy.length.shorthold", min_tenancy_length:) : I18n.t("validations.tenancy.length.secure", min_tenancy_length:) message = I18n.t("validations.tenancy.length.invalid_fixed", min_tenancy_length:)
record.errors.add :needstype, message record.errors.add :needstype, message
record.errors.add :rent_type, message record.errors.add :rent_type, message
record.errors.add :tenancylength, :tenancylength_invalid, message: message record.errors.add :tenancylength, :tenancylength_invalid, message: message
@ -26,7 +26,7 @@ module Validations::TenancyValidations
min_tenancy_length = 2 min_tenancy_length = 2
return if record.tenancylength.to_i.between?(min_tenancy_length, 99) return if record.tenancylength.to_i.between?(min_tenancy_length, 99)
message = record.is_assured_shorthold_tenancy? ? I18n.t("validations.tenancy.length.shorthold", min_tenancy_length:) : I18n.t("validations.tenancy.length.secure", min_tenancy_length:) message = I18n.t("validations.tenancy.length.invalid_fixed", min_tenancy_length:)
record.errors.add :needstype, message record.errors.add :needstype, message
record.errors.add :rent_type, message record.errors.add :rent_type, message
record.errors.add :tenancylength, :tenancylength_invalid, message: message record.errors.add :tenancylength, :tenancylength_invalid, message: message
@ -40,7 +40,7 @@ module Validations::TenancyValidations
min_tenancy_length = 1 min_tenancy_length = 1
return if record.tenancylength.to_i.between?(min_tenancy_length, 99) return if record.tenancylength.to_i.between?(min_tenancy_length, 99)
message = record.is_assured_shorthold_tenancy? ? I18n.t("validations.tenancy.length.shorthold", min_tenancy_length:) : I18n.t("validations.tenancy.length.secure", min_tenancy_length:) message = I18n.t("validations.tenancy.length.invalid_fixed", min_tenancy_length:)
record.errors.add :needstype, message record.errors.add :needstype, message
record.errors.add :rent_type, message record.errors.add :rent_type, message
record.errors.add :tenancylength, :tenancylength_invalid, message: message record.errors.add :tenancylength, :tenancylength_invalid, message: message
@ -53,7 +53,7 @@ module Validations::TenancyValidations
min_tenancy_length = 1 min_tenancy_length = 1
return if record.tenancylength.to_i.between?(min_tenancy_length, 99) return if record.tenancylength.to_i.between?(min_tenancy_length, 99)
message = I18n.t("validations.tenancy.length.secure", min_tenancy_length:) message = I18n.t("validations.tenancy.length.invalid_periodic", min_tenancy_length:)
record.errors.add :tenancylength, :tenancylength_invalid, message: message record.errors.add :tenancylength, :tenancylength_invalid, message: message
record.errors.add :tenancy, message record.errors.add :tenancy, message
end end

4
config/locales/en.yml

@ -557,8 +557,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 tenancy of this type" invalid_fixed: "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 tenancy of this type" invalid_periodic: "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"

6
spec/models/validations/tenancy_validations_spec.rb

@ -76,13 +76,13 @@ RSpec.describe Validations::TenancyValidations do
{ {
name: "assured shorthold", name: "assured shorthold",
code: 4, code: 4,
expected_error: ->(min_tenancy_length) { I18n.t("validations.tenancy.length.shorthold", min_tenancy_length:) }, expected_error: ->(min_tenancy_length) { I18n.t("validations.tenancy.length.invalid_fixed", min_tenancy_length:) },
error_fields: %w[needstype rent_type tenancylength tenancy], error_fields: %w[needstype rent_type tenancylength tenancy],
}, },
{ {
name: "secure fixed term", name: "secure fixed term",
code: 6, code: 6,
expected_error: ->(min_tenancy_length) { I18n.t("validations.tenancy.length.secure", min_tenancy_length:) }, expected_error: ->(min_tenancy_length) { I18n.t("validations.tenancy.length.invalid_fixed", min_tenancy_length:) },
error_fields: %w[needstype rent_type tenancylength tenancy], error_fields: %w[needstype rent_type tenancylength tenancy],
}, },
] ]
@ -210,7 +210,7 @@ RSpec.describe Validations::TenancyValidations do
periodic_tenancy_case = { periodic_tenancy_case = {
name: "periodic", name: "periodic",
code: 8, code: 8,
expected_error: ->(min_tenancy_length) { I18n.t("validations.tenancy.length.secure", min_tenancy_length:) }, expected_error: ->(min_tenancy_length) { I18n.t("validations.tenancy.length.invalid_periodic", min_tenancy_length:) },
error_fields: %w[tenancylength tenancy], error_fields: %w[tenancylength tenancy],
} }
include_examples "adds expected errors based on the tenancy length", periodic_tenancy_case, 1 include_examples "adds expected errors based on the tenancy length", periodic_tenancy_case, 1

Loading…
Cancel
Save