Browse Source

Rename functions for clarity

pull/2295/head
Rachael Booth 2 years ago
parent
commit
d7199bdbf9
  1. 10
      app/models/validations/tenancy_validations.rb
  2. 8
      spec/models/lettings_log_spec.rb
  3. 16
      spec/models/validations/tenancy_validations_spec.rb

10
app/models/validations/tenancy_validations.rb

@ -3,9 +3,7 @@ module Validations::TenancyValidations
# or 'validate_' to run on submit as well # or 'validate_' to run on submit as well
include Validations::SharedValidations include Validations::SharedValidations
# N.B. To match the page split and naming, this is the supported housing case def validate_supported_housing_fixed_tenancy_length(record)
# General needs cases are in the other validations below
def validate_tenancy_length(record)
return unless record.tenancy_type_fixed_term? && record.is_supported_housing? return unless record.tenancy_type_fixed_term? && record.is_supported_housing?
return if record.tenancylength.blank? return if record.tenancylength.blank?
@ -18,7 +16,7 @@ module Validations::TenancyValidations
record.errors.add :tenancy, message record.errors.add :tenancy, message
end 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 unless record.tenancy_type_fixed_term? && record.affordable_or_social_rent? && record.is_general_needs?
return if record.tenancylength.blank? return if record.tenancylength.blank?
@ -32,7 +30,7 @@ module Validations::TenancyValidations
record.errors.add :tenancy, message record.errors.add :tenancy, message
end 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 unless record.tenancy_type_fixed_term? && !record.affordable_or_social_rent? && record.is_general_needs?
return if record.tenancylength.blank? return if record.tenancylength.blank?
@ -46,7 +44,7 @@ module Validations::TenancyValidations
record.errors.add :tenancy, message record.errors.add :tenancy, message
end end
def validate_tenancy_length_periodic(record) def validate_periodic_tenancy_length(record)
return unless record.is_periodic_tenancy? && record.tenancylength.present? return unless record.is_periodic_tenancy? && record.tenancylength.present?
min_tenancy_length = 1 min_tenancy_length = 1

8
spec/models/lettings_log_spec.rb

@ -116,10 +116,10 @@ RSpec.describe LettingsLog do
end end
it "validates tenancy length" do it "validates tenancy length" do
expect(validator).to receive(:validate_tenancy_length) expect(validator).to receive(:validate_supported_housing_fixed_tenancy_length)
expect(validator).to receive(:validate_tenancy_length_affordable_rent) expect(validator).to receive(:validate_general_needs_fixed_tenancy_length_affordable_social_rent)
expect(validator).to receive(:validate_tenancy_length_intermediate_rent) expect(validator).to receive(:validate_general_needs_fixed_tenancy_length_intermediate_rent)
expect(validator).to receive(:validate_tenancy_length_periodic) expect(validator).to receive(:validate_periodic_tenancy_length)
expect(validator).to receive(:validate_tenancy_length_blank_when_not_required) expect(validator).to receive(:validate_tenancy_length_blank_when_not_required)
end end

16
spec/models/validations/tenancy_validations_spec.rb

@ -85,8 +85,8 @@ RSpec.describe Validations::TenancyValidations do
}, },
] ]
describe "#validate_tenancy_length" do describe "#validate_supported_housing_fixed_tenancy_length" do
subject(:validation) { ->(record) { tenancy_validator.validate_tenancy_length(record) } } subject(:validation) { ->(record) { tenancy_validator.validate_supported_housing_fixed_tenancy_length(record) } }
context "when needs type is supported housing" do context "when needs type is supported housing" do
before { record.needstype = 2 } before { record.needstype = 2 }
@ -113,8 +113,8 @@ RSpec.describe Validations::TenancyValidations do
end end
end end
describe "#validate_tenancy_length_affordable_rent" do describe "#validate_general_needs_fixed_tenancy_length_affordable_social_rent" do
subject(:validation) { ->(record) { tenancy_validator.validate_tenancy_length_affordable_rent(record) } } subject(:validation) { ->(record) { tenancy_validator.validate_general_needs_fixed_tenancy_length_affordable_social_rent(record) } }
context "when needs type is general needs" do context "when needs type is general needs" do
before { record.needstype = 1 } before { record.needstype = 1 }
@ -159,8 +159,8 @@ RSpec.describe Validations::TenancyValidations do
end end
end end
describe "#validate_tenancy_length_intermediate_rent" do describe "#validate_general_needs_fixed_tenancy_length_intermediate_rent" do
subject(:validation) { ->(record) { tenancy_validator.validate_tenancy_length_intermediate_rent(record) } } subject(:validation) { ->(record) { tenancy_validator.validate_general_needs_fixed_tenancy_length_intermediate_rent(record) } }
context "when needs type is general needs" do context "when needs type is general needs" do
before { record.needstype = 1 } before { record.needstype = 1 }
@ -205,8 +205,8 @@ RSpec.describe Validations::TenancyValidations do
end end
end end
describe "#validate_tenancy_length_periodic" do describe "#validate_periodic_tenancy_length" do
subject(:validation) { ->(record) { tenancy_validator.validate_tenancy_length_periodic(record) } } subject(:validation) { ->(record) { tenancy_validator.validate_periodic_tenancy_length(record) } }
periodic_tenancy_case = { periodic_tenancy_case = {
name: "periodic", name: "periodic",

Loading…
Cancel
Save