diff --git a/app/models/validations/tenancy_validations.rb b/app/models/validations/tenancy_validations.rb index 2950adba3..bd55203fb 100644 --- a/app/models/validations/tenancy_validations.rb +++ b/app/models/validations/tenancy_validations.rb @@ -3,9 +3,7 @@ module Validations::TenancyValidations # or 'validate_' to run on submit as well include Validations::SharedValidations - # N.B. To match the page split and naming, this is the supported housing case - # General needs cases are in the other validations below - def validate_tenancy_length(record) + def validate_supported_housing_fixed_tenancy_length(record) return unless record.tenancy_type_fixed_term? && record.is_supported_housing? return if record.tenancylength.blank? @@ -18,7 +16,7 @@ module Validations::TenancyValidations record.errors.add :tenancy, message end - def validate_tenancy_length_affordable_rent(record) + def validate_general_needs_fixed_tenancy_length_affordable_social_rent(record) return unless record.tenancy_type_fixed_term? && record.affordable_or_social_rent? && record.is_general_needs? return if record.tenancylength.blank? @@ -32,7 +30,7 @@ module Validations::TenancyValidations record.errors.add :tenancy, message end - def validate_tenancy_length_intermediate_rent(record) + def validate_general_needs_fixed_tenancy_length_intermediate_rent(record) return unless record.tenancy_type_fixed_term? && !record.affordable_or_social_rent? && record.is_general_needs? return if record.tenancylength.blank? @@ -46,7 +44,7 @@ module Validations::TenancyValidations record.errors.add :tenancy, message end - def validate_tenancy_length_periodic(record) + def validate_periodic_tenancy_length(record) return unless record.is_periodic_tenancy? && record.tenancylength.present? min_tenancy_length = 1 diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index e38a235e7..47e1203df 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -116,10 +116,10 @@ RSpec.describe LettingsLog do end it "validates tenancy length" do - expect(validator).to receive(:validate_tenancy_length) - expect(validator).to receive(:validate_tenancy_length_affordable_rent) - expect(validator).to receive(:validate_tenancy_length_intermediate_rent) - expect(validator).to receive(:validate_tenancy_length_periodic) + expect(validator).to receive(:validate_supported_housing_fixed_tenancy_length) + expect(validator).to receive(:validate_general_needs_fixed_tenancy_length_affordable_social_rent) + expect(validator).to receive(:validate_general_needs_fixed_tenancy_length_intermediate_rent) + expect(validator).to receive(:validate_periodic_tenancy_length) expect(validator).to receive(:validate_tenancy_length_blank_when_not_required) end diff --git a/spec/models/validations/tenancy_validations_spec.rb b/spec/models/validations/tenancy_validations_spec.rb index 7b41e890b..f5ffc05b0 100644 --- a/spec/models/validations/tenancy_validations_spec.rb +++ b/spec/models/validations/tenancy_validations_spec.rb @@ -85,8 +85,8 @@ RSpec.describe Validations::TenancyValidations do }, ] - describe "#validate_tenancy_length" do - subject(:validation) { ->(record) { tenancy_validator.validate_tenancy_length(record) } } + describe "#validate_supported_housing_fixed_tenancy_length" do + subject(:validation) { ->(record) { tenancy_validator.validate_supported_housing_fixed_tenancy_length(record) } } context "when needs type is supported housing" do before { record.needstype = 2 } @@ -113,8 +113,8 @@ RSpec.describe Validations::TenancyValidations do end end - describe "#validate_tenancy_length_affordable_rent" do - subject(:validation) { ->(record) { tenancy_validator.validate_tenancy_length_affordable_rent(record) } } + describe "#validate_general_needs_fixed_tenancy_length_affordable_social_rent" do + subject(:validation) { ->(record) { tenancy_validator.validate_general_needs_fixed_tenancy_length_affordable_social_rent(record) } } context "when needs type is general needs" do before { record.needstype = 1 } @@ -159,8 +159,8 @@ RSpec.describe Validations::TenancyValidations do end end - describe "#validate_tenancy_length_intermediate_rent" do - subject(:validation) { ->(record) { tenancy_validator.validate_tenancy_length_intermediate_rent(record) } } + describe "#validate_general_needs_fixed_tenancy_length_intermediate_rent" do + subject(:validation) { ->(record) { tenancy_validator.validate_general_needs_fixed_tenancy_length_intermediate_rent(record) } } context "when needs type is general needs" do before { record.needstype = 1 } @@ -205,8 +205,8 @@ RSpec.describe Validations::TenancyValidations do end end - describe "#validate_tenancy_length_periodic" do - subject(:validation) { ->(record) { tenancy_validator.validate_tenancy_length_periodic(record) } } + describe "#validate_periodic_tenancy_length" do + subject(:validation) { ->(record) { tenancy_validator.validate_periodic_tenancy_length(record) } } periodic_tenancy_case = { name: "periodic",