Browse Source

Don't validate tenancy length if not answered yet

pull/296/head
baarkerlounger 3 years ago
parent
commit
1a4a4dfdb2
  1. 2
      app/models/validations/tenancy_validations.rb
  2. 24
      spec/models/validations/tenancy_validations_spec.rb

2
app/models/validations/tenancy_validations.rb

@ -8,7 +8,7 @@ module Validations::TenancyValidations
is_ast = record.tenancy == "Assured Shorthold"
conditions = [
{ condition: !(is_secure || is_ast) && is_present, error: I18n.t("validations.tenancy.length.fixed_term_not_required") },
{ condition: is_ast && !is_in_range, error: I18n.t("validations.tenancy.length.shorthold") },
{ condition: (is_ast && !is_in_range) && is_present, error: I18n.t("validations.tenancy.length.shorthold") },
{ condition: is_secure && (!is_in_range && is_present), error: I18n.t("validations.tenancy.length.secure") },
]

24
spec/models/validations/tenancy_validations_spec.rb

@ -44,7 +44,7 @@ RSpec.describe Validations::TenancyValidations do
end
context "when tenancy length is between 2-99" do
it "adds an error" do
it "does not add an error" do
record.tenancy = "Assured Shorthold"
record.tenancylength = 3
subject.validate_fixed_term_tenancy(record)
@ -52,6 +52,16 @@ RSpec.describe Validations::TenancyValidations do
expect(record.errors["tenancy"]).to be_empty
end
end
context "when tenancy length has not been answered" do
it "does not add an error" do
record.tenancy = "Assured Shorthold"
record.tenancylength = nil
subject.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to be_empty
expect(record.errors["tenancy"]).to be_empty
end
end
end
context "when type of tenancy is secure" do
@ -78,7 +88,7 @@ RSpec.describe Validations::TenancyValidations do
end
context "when tenancy length is between 2-99" do
it "adds an error" do
it "does not add an error" do
record.tenancy = "Secure (including flexible)"
record.tenancylength = 3
subject.validate_fixed_term_tenancy(record)
@ -86,6 +96,16 @@ RSpec.describe Validations::TenancyValidations do
expect(record.errors["tenancy"]).to be_empty
end
end
context "when tenancy length has not been answered" do
it "does not add an error" do
record.tenancy = "Secure (including flexible)"
record.tenancylength = nil
subject.validate_fixed_term_tenancy(record)
expect(record.errors["tenancylength"]).to be_empty
expect(record.errors["tenancy"]).to be_empty
end
end
end
end
end

Loading…
Cancel
Save