diff --git a/app/models/validations/tenancy_validations.rb b/app/models/validations/tenancy_validations.rb index bd55203fb..ffab51e92 100644 --- a/app/models/validations/tenancy_validations.rb +++ b/app/models/validations/tenancy_validations.rb @@ -10,7 +10,7 @@ module Validations::TenancyValidations min_tenancy_length = 1 return if record.tenancylength.to_i.between?(min_tenancy_length, 99) - message = I18n.t("validations.tenancy.length.invalid_fixed", min_tenancy_length:) + message = I18n.t("validations.lettings.tenancy.length.invalid_fixed", min_tenancy_length:) record.errors.add :needstype, message record.errors.add :tenancylength, :tenancylength_invalid, message: message record.errors.add :tenancy, message @@ -23,7 +23,7 @@ module Validations::TenancyValidations min_tenancy_length = 2 return if record.tenancylength.to_i.between?(min_tenancy_length, 99) - message = I18n.t("validations.tenancy.length.invalid_fixed", min_tenancy_length:) + message = I18n.t("validations.lettings.tenancy.length.invalid_fixed", min_tenancy_length:) record.errors.add :needstype, message record.errors.add :rent_type, message record.errors.add :tenancylength, :tenancylength_invalid, message: message @@ -37,7 +37,7 @@ module Validations::TenancyValidations min_tenancy_length = 1 return if record.tenancylength.to_i.between?(min_tenancy_length, 99) - message = I18n.t("validations.tenancy.length.invalid_fixed", min_tenancy_length:) + message = I18n.t("validations.lettings.tenancy.length.invalid_fixed", min_tenancy_length:) record.errors.add :needstype, message record.errors.add :rent_type, message record.errors.add :tenancylength, :tenancylength_invalid, message: message @@ -50,7 +50,7 @@ module Validations::TenancyValidations min_tenancy_length = 1 return if record.tenancylength.to_i.between?(min_tenancy_length, 99) - message = I18n.t("validations.tenancy.length.invalid_periodic", min_tenancy_length:) + message = I18n.t("validations.lettings.tenancy.length.invalid_periodic", min_tenancy_length:) record.errors.add :tenancylength, :tenancylength_invalid, message: message record.errors.add :tenancy, message end @@ -59,7 +59,7 @@ module Validations::TenancyValidations return if record.tenancylength.blank? return if record.tenancy_type_fixed_term? || record.is_periodic_tenancy? - message = I18n.t("validations.tenancy.length.fixed_term_not_required") + message = I18n.t("validations.lettings.tenancy.length.fixed_term_not_required") record.errors.add :tenancylength, :tenancylength_invalid, message: message record.errors.add :tenancy, message end @@ -72,8 +72,8 @@ module Validations::TenancyValidations return unless record.collection_start_year && record.joint if record.hhmemb == 1 && record.joint == 1 && record.collection_start_year >= 2022 - record.errors.add :joint, :not_joint_tenancy, message: I18n.t("validations.tenancy.not_joint") - record.errors.add :hhmemb, I18n.t("validations.tenancy.joint_more_than_one_member") + record.errors.add :joint, :not_joint_tenancy, message: I18n.t("validations.lettings.tenancy.joint.sole_tenancy") + record.errors.add :hhmemb, I18n.t("validations.lettings.tenancy.joint.multiple_members_required") end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 7ed8f42e8..00daa90bc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -234,7 +234,7 @@ en: scheme_deleted: "%{service_name} has been deleted." user_deleted: "%{name} has been deleted." organisation_deleted: "%{name} has been deleted." - user_updated: + user_updated: self: "Your account details have been updated." other: "%{name}’s details have been updated." @@ -585,14 +585,8 @@ en: nationality: "Select a valid nationality." tenancy: - length: - fixed_term_not_required: "You must only answer the length of the tenancy if it's fixed-term." - invalid_fixed: "Enter a tenancy length between %{min_tenancy_length} and 99 years 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." 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." - joint_more_than_one_member: "There must be more than one person in the household as you've told us this is a joint tenancy." declaration: missing: diff --git a/config/locales/validations/lettings/tenancy.en.yml b/config/locales/validations/lettings/tenancy.en.yml new file mode 100644 index 000000000..7c584c88c --- /dev/null +++ b/config/locales/validations/lettings/tenancy.en.yml @@ -0,0 +1,11 @@ +en: + validations: + lettings: + tenancy: + length: + fixed_term_not_required: "You must only answer the length of the tenancy if it's fixed-term." + invalid_fixed: "Enter a tenancy length between %{min_tenancy_length} and 99 years 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." + joint: + sole_tenancy: "This cannot be a joint tenancy as you've told us there's only one person in the household." + multiple_members_required: "There must be more than one person in the household as you've told us this is a joint tenancy." diff --git a/spec/models/validations/tenancy_validations_spec.rb b/spec/models/validations/tenancy_validations_spec.rb index a41752616..7a3a45bd9 100644 --- a/spec/models/validations/tenancy_validations_spec.rb +++ b/spec/models/validations/tenancy_validations_spec.rb @@ -76,12 +76,12 @@ RSpec.describe Validations::TenancyValidations do { name: "assured shorthold", code: 4, - expected_error: ->(min_tenancy_length) { I18n.t("validations.tenancy.length.invalid_fixed", min_tenancy_length:) }, + expected_error: ->(min_tenancy_length) { I18n.t("validations.lettings.tenancy.length.invalid_fixed", min_tenancy_length:) }, }, { name: "secure fixed term", code: 6, - expected_error: ->(min_tenancy_length) { I18n.t("validations.tenancy.length.invalid_fixed", min_tenancy_length:) }, + expected_error: ->(min_tenancy_length) { I18n.t("validations.lettings.tenancy.length.invalid_fixed", min_tenancy_length:) }, }, ] @@ -211,7 +211,7 @@ RSpec.describe Validations::TenancyValidations do periodic_tenancy_case = { name: "periodic", code: 8, - expected_error: ->(min_tenancy_length) { I18n.t("validations.tenancy.length.invalid_periodic", min_tenancy_length:) }, + expected_error: ->(min_tenancy_length) { I18n.t("validations.lettings.tenancy.length.invalid_periodic", min_tenancy_length:) }, } error_fields = %w[tenancylength tenancy] include_examples "adds expected errors based on the tenancy length", periodic_tenancy_case, error_fields, 1 @@ -237,7 +237,7 @@ RSpec.describe Validations::TenancyValidations do it "adds errors to tenancylength and tenancy" do tenancy_validator.validate_tenancy_length_blank_when_not_required(record) - expected_error = I18n.t("validations.tenancy.length.fixed_term_not_required") + expected_error = I18n.t("validations.lettings.tenancy.length.fixed_term_not_required") expect(record.errors["tenancylength"]).to include(expected_error) expect(record.errors["tenancy"]).to include(expected_error) end @@ -321,8 +321,8 @@ RSpec.describe Validations::TenancyValidations do describe "joint tenancy validation" do context "when the data inputter has said that there is only one member in the household" do let(:record) { FactoryBot.build(:lettings_log, :setup_completed, hhmemb: 1) } - let(:expected_error) { I18n.t("validations.tenancy.not_joint") } - let(:hhmemb_expected_error) { I18n.t("validations.tenancy.joint_more_than_one_member") } + let(:expected_error) { I18n.t("validations.lettings.tenancy.joint.sole_tenancy") } + let(:hhmemb_expected_error) { I18n.t("validations.lettings.tenancy.joint.multiple_members_required") } it "displays an error if the data inputter says the letting is a joint tenancy" do record.joint = 1