Browse Source

Fix the tests and validations

pull/91/head
Kat 4 years ago
parent
commit
efd69eff76
  1. 2
      app/models/case_log.rb
  2. 6
      app/validations/tenancy_validations.rb
  3. 2
      docs/api/DLUHC-CORE-Data.v1.json
  4. 2
      spec/fixtures/complete_case_log.json
  5. 18
      spec/models/case_log_spec.rb

2
app/models/case_log.rb

@ -230,7 +230,7 @@ private
dynamically_not_required << "incfreq"
end
if tenancy == "Fixed term – Secure"
if tenancy == "Secure (including flexible)"
dynamically_not_required << "tenancylength"
end

6
app/validations/tenancy_validations.rb

@ -4,12 +4,12 @@ module TenancyValidations
def validate_fixed_term_tenancy(record)
is_present = record.tenancylength.present?
is_in_range = record.tenancylength.to_i.between?(2, 99)
is_secure = record.tenancy == "Fixed term – Secure"
is_ast = record.tenancy == "Fixed term – Assured Shorthold Tenancy (AST)"
is_secure = record.tenancy == "Secure (including flexible)"
is_ast = record.tenancy == "Assured Shorthold"
conditions = [
{ condition: !(is_secure || is_ast) && is_present, error: "You must only answer the fixed term tenancy length question if the tenancy type is fixed term" },
{ condition: is_ast && !is_in_range, error: "Fixed term – Assured Shorthold Tenancy (AST) should be between 2 and 99 years" },
{ condition: is_secure && (!is_in_range && is_present), error: "Fixed term – Secure should be between 2 and 99 years or not specified" },
{ condition: is_secure && (!is_in_range && is_present), error: "Secure (including flexible) should be between 2 and 99 years or not specified" },
]
conditions.each { |condition| condition[:condition] ? (record.errors.add :tenancylength, condition[:error]) : nil }

2
docs/api/DLUHC-CORE-Data.v1.json

@ -306,7 +306,7 @@
"startdate": "12/03/2019",
"startertenancy": "No",
"tenancylength": "No",
"tenancy": "Fixed term – Secure",
"tenancy": "Secure (including flexible)",
"lettype": "Affordable Rent - General Needs",
"landlord": "This landlord",
"la": "Barnet",

2
spec/fixtures/complete_case_log.json vendored

@ -52,7 +52,7 @@
"startdate": "12/03/2019",
"startertenancy": "No",
"tenancylength": "5",
"tenancy": "Fixed term – Secure",
"tenancy": "Secure (including flexible)",
"lettype": "Affordable Rent - General Needs",
"landlord": "This landlord",
"la": "Barnet",

18
spec/models/case_log_spec.rb

@ -182,39 +182,39 @@ RSpec.describe Form, type: :model do
it "Must be completed and between 2 and 99 if type of tenancy is Assured shorthold" do
expect {
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)",
CaseLog.create!(tenancy: "Assured Shorthold",
tenancylength: 1)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)",
CaseLog.create!(tenancy: "Assured Shorthold",
tenancylength: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)",
CaseLog.create!(tenancy: "Assured Shorthold",
tenancylength: 2)
}.not_to raise_error
end
it "Must be empty or between 2 and 99 if type of tenancy is Secure" do
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: 1)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: 100)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: nil)
}.not_to raise_error
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: 2)
}.not_to raise_error
end
@ -294,12 +294,12 @@ RSpec.describe Form, type: :model do
it "must not be provided if tenancy type is not other" do
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancyother: "the other reason provided")
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancyother: nil)
}.not_to raise_error
end

Loading…
Cancel
Save