Browse Source

Merge pull request #65 from communitiesuk/CLDC-493-OutstandingRentAmount-Validation

added simple validation for outstanding rent
pull/64/head^2
Milo 3 years ago committed by GitHub
parent
commit
562883495d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/models/case_log.rb
  2. 15
      docs/api/DLUHC-CORE-Data.v1.json
  3. 16
      spec/models/case_log_spec.rb

11
app/models/case_log.rb

@ -55,6 +55,15 @@ class CaseLogValidator < ActiveModel::Validator
end
end
def validate_outstanding_rent_amount(record)
if record.outstanding_rent_or_charges == "Yes" && record.outstanding_amount.blank?
record.errors.add :outstanding_amount, "You must answer the oustanding amout question if you have outstanding rent or charges."
end
if record.outstanding_rent_or_charges == "No" && record.outstanding_amount.present?
record.errors.add :outstanding_amount, "You must not answer the oustanding amout question if you don't have outstanding rent or charges."
end
end
EMPLOYED_STATUSES = ["Full-time - 30 hours or more", "Part-time - Less than 30 hours"].freeze
def validate_net_income_uc_proportion(record)
(1..8).any? do |n|
@ -67,7 +76,7 @@ class CaseLogValidator < ActiveModel::Validator
end
end
end
def validate_household_pregnancy(record)
if (record.pregnancy == "Yes" || record.pregnancy == "Prefer not to say") && !women_of_child_bearing_age_in_household(record)
record.errors.add :pregnancy, "You must answer no as there are no female tenants aged 16-50 in the property"

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

@ -1207,6 +1207,17 @@
]
}
},
"securitySchemes": {}
"securitySchemes": {
"API Key - 1": {
"name": "API Key",
"type": "apiKey",
"in": "query"
},
"API Key - 2": {
"name": "API Key",
"type": "apiKey",
"in": "query"
}
}
}
}
}

16
spec/models/case_log_spec.rb

@ -97,6 +97,22 @@ RSpec.describe Form, type: :model do
end
end
context "outstanding rent or charges validation" do
it "must be anwered if answered yes to outstanding rent or charges" do
expect {
CaseLog.create!(outstanding_rent_or_charges: "Yes",
outstanding_amount: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must be not be anwered if answered no to outstanding rent or charges" do
expect {
CaseLog.create!(outstanding_rent_or_charges: "No",
outstanding_amount: 99)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "tenant’s income is from Universal Credit, state pensions or benefits" do
it "Cannot be All if person 1 works full time" do
expect {

Loading…
Cancel
Save