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
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

8
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

16
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",

Loading…
Cancel
Save