Browse Source

Tenancy type validation

pull/304/head
baarkerlounger 3 years ago
parent
commit
0a26315d0f
  1. 37
      spec/models/case_log_spec.rb
  2. 43
      spec/models/validations/tenancy_validations_spec.rb

37
spec/models/case_log_spec.rb

@ -171,40 +171,6 @@ RSpec.describe CaseLog do
end
end
context "when validating other tenancy type" do
it "must be provided if tenancy type was given as other" do
expect {
described_class.create!(tenancy: "Other",
tenancyother: nil,
owning_organisation:,
managing_organisation:)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
described_class.create!(tenancy: "Other",
tenancyother: "type",
owning_organisation:,
managing_organisation:)
}.not_to raise_error
end
it "must not be provided if tenancy type is not other" do
expect {
described_class.create!(tenancy: "Secure (including flexible)",
tenancyother: "the other reason provided",
owning_organisation:,
managing_organisation:)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
described_class.create!(tenancy: "Secure (including flexible)",
tenancyother: nil,
owning_organisation:,
managing_organisation:)
}.not_to raise_error
end
end
context "when saving income ranges" do
it "validates net income maximum" do
expect {
@ -398,8 +364,9 @@ RSpec.describe CaseLog do
expect(validator).to receive(:validate_property_number_of_times_relet)
end
it "validates tenancy length for tenancy type" do
it "validates tenancy type" do
expect(validator).to receive(:validate_fixed_term_tenancy)
expect(validator).to receive(:validate_other_tenancy_type)
end
it "validates the previous postcode" do

43
spec/models/validations/tenancy_validations_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Validations::TenancyValidations do
let(:validator_class) { Class.new { include Validations::TenancyValidations } }
let(:record) { FactoryBot.create(:case_log) }
describe "#validate_fixed_term_tenancy" do
describe "fixed term tenancy validations" do
context "when fixed term tenancy" do
context "when type of tenancy is not assured or assured shorthold" do
let(:expected_error) { I18n.t("validations.tenancy.length.fixed_term_not_required") }
@ -109,4 +109,45 @@ RSpec.describe Validations::TenancyValidations do
end
end
end
describe "tenancy type validations" do
let(:field) { "validations.other_field_missing" }
let(:main_field_label) { "tenancy" }
let(:other_field_label) { "tenancyother" }
let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) }
context "when tenancy type is other" do
it "validates that other tenancy type is provided" do
record.tenancy = "Other"
record.tenancyother = nil
tenancy_validator.validate_other_tenancy_type(record)
expect(record.errors[other_field_label]).to include(match(expected_error))
end
it "expects that other tenancy type is provided" do
record.tenancy = "Other"
record.tenancyother = "Some other tenancy type"
tenancy_validator.validate_other_tenancy_type(record)
expect(record.errors[other_field_label]).to be_empty
end
end
context "when tenancy type is not other" do
let(:field) { "validations.other_field_not_required" }
it "validates that other tenancy type is not provided" do
record.tenancy = "Assured"
record.tenancyother = "Some other tenancy type"
tenancy_validator.validate_other_tenancy_type(record)
expect(record.errors[other_field_label]).to include(match(expected_error))
end
it "expects that other tenancy type is not provided" do
record.tenancy = "Secure (including flexible)"
record.tenancyother = nil
tenancy_validator.validate_other_tenancy_type(record)
expect(record.errors[other_field_label]).to be_empty
end
end
end
end

Loading…
Cancel
Save