Browse Source

CLDC-473: Add net income uc proportion validation (#62)

* Add validate_net_income_uc_proportion validation/

* refactor validation method;

* Update net income options in doc

* rubocop

* refactor validate_net_income_uc_proportion and increase the persons checked to 8

* rename tenant economic status field
pull/67/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
2c1f246350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      app/models/case_log.rb
  2. 2
      config/forms/2021_2022.json
  3. 7
      db/migrate/20211027091521_rename_person1_fields.rb
  4. 4
      db/schema.rb
  5. 14
      docs/api/DLUHC-CORE-Data.v1.json
  6. 2
      spec/fixtures/complete_case_log.json
  7. 20
      spec/models/case_log_spec.rb

13
app/models/case_log.rb

@ -55,6 +55,19 @@ class CaseLogValidator < ActiveModel::Validator
end end
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|
economic_status = record["person_#{n}_economic_status"]
is_employed = EMPLOYED_STATUSES.include?(economic_status)
relationship = record["person_#{n}_relationship"]
is_partner_or_main = relationship == "Partner" || (relationship.nil? && economic_status.present?)
if is_employed && is_partner_or_main && record.net_income_uc_proportion == "All"
record.errors.add :net_income_uc_proportion, "income is from Universal Credit, state pensions or benefits cannot be All if the tenant or the partner works part or full time"
end
end
end
def validate_household_pregnancy(record) def validate_household_pregnancy(record)
if (record.pregnancy == "Yes" || record.pregnancy == "Prefer not to say") && !women_of_child_bearing_age_in_household(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" record.errors.add :pregnancy, "You must answer no as there are no female tenants aged 16-50 in the property"

2
config/forms/2021_2022.json

@ -121,7 +121,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"tenant_economic_status": { "person_1_economic_status": {
"check_answer_label": "Work", "check_answer_label": "Work",
"header": "Which of these best describes the tenant's working situation?", "header": "Which of these best describes the tenant's working situation?",
"hint_text": "", "hint_text": "",

7
db/migrate/20211027091521_rename_person1_fields.rb

@ -0,0 +1,7 @@
class RenamePerson1Fields < ActiveRecord::Migration[6.1]
def change
change_table :case_logs, bulk: true do |t|
t.rename :tenant_economic_status, :person_1_economic_status
end
end
end

4
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_10_26_123542) do ActiveRecord::Schema.define(version: 2021_10_27_091521) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -26,7 +26,7 @@ ActiveRecord::Schema.define(version: 2021_10_26_123542) do
t.string "tenant_nationality" t.string "tenant_nationality"
t.string "previous_housing_situation" t.string "previous_housing_situation"
t.string "armed_forces" t.string "armed_forces"
t.string "tenant_economic_status" t.string "person_1_economic_status"
t.integer "household_number_of_other_members" t.integer "household_number_of_other_members"
t.string "person_2_relationship" t.string "person_2_relationship"
t.integer "person_2_age" t.integer "person_2_age"

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

@ -274,7 +274,7 @@
"tenant_nationality": "UK national resident in UK", "tenant_nationality": "UK national resident in UK",
"previous_housing_situation": "Private sector tenancy", "previous_housing_situation": "Private sector tenancy",
"armed_forces": "Yes - a regular", "armed_forces": "Yes - a regular",
"tenant_economic_status": "Full-time - 30 hours or more", "person_1_economic_status": "Full-time - 30 hours or more",
"household_number_of_other_members": 7, "household_number_of_other_members": 7,
"person_2_relationship": "Partner", "person_2_relationship": "Partner",
"person_2_age": 32, "person_2_age": 32,
@ -459,7 +459,7 @@
"type": "string", "type": "string",
"minLength": 1 "minLength": 1
}, },
"tenant_economic_status": { "person_1_economic_status": {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
"enum": [ "enum": [
@ -945,7 +945,13 @@
}, },
"net_income_uc_proportion": { "net_income_uc_proportion": {
"type": "string", "type": "string",
"minLength": 1 "minLength": 1,
"enum": [
"All",
"Some",
"None",
"Do not know"
]
}, },
"housing_benefit": { "housing_benefit": {
"type": "string", "type": "string",
@ -1092,7 +1098,7 @@
"tenant_nationality", "tenant_nationality",
"previous_housing_situation", "previous_housing_situation",
"armed_forces", "armed_forces",
"tenant_economic_status", "person_1_economic_status",
"household_number_of_other_members", "household_number_of_other_members",
"person_2_relationship", "person_2_relationship",
"person_2_age", "person_2_age",

2
spec/fixtures/complete_case_log.json vendored

@ -8,7 +8,7 @@
"tenant_nationality": "UK national resident in UK", "tenant_nationality": "UK national resident in UK",
"previous_housing_situation": "Private sector tenancy", "previous_housing_situation": "Private sector tenancy",
"armed_forces": "Yes - a regular", "armed_forces": "Yes - a regular",
"tenant_economic_status": "Full-time - 30 hours or more", "person_1_economic_status": "Full-time - 30 hours or more",
"household_number_of_other_members": 7, "household_number_of_other_members": 7,
"person_2_relationship": "Partner", "person_2_relationship": "Partner",
"person_2_age": 32, "person_2_age": 32,

20
spec/models/case_log_spec.rb

@ -96,6 +96,26 @@ RSpec.describe Form, type: :model do
}.to raise_error(ActiveRecord::RecordInvalid) }.to raise_error(ActiveRecord::RecordInvalid)
end end
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 {
CaseLog.create!(net_income_uc_proportion: "All", person_1_economic_status: "Full-time - 30 hours or more")
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "Cannot be All if person 1 works part time" do
expect {
CaseLog.create!(net_income_uc_proportion: "All", person_1_economic_status: "Part-time - Less than 30 hours")
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "Cannot be 1 All if any of persons 2-4 are person 1's partner and work part or full time" do
expect {
CaseLog.create!(net_income_uc_proportion: "All", person_2_relationship: "Partner", person_2_economic_status: "Part-time - Less than 30 hours")
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
end end
describe "status" do describe "status" do

Loading…
Cancel
Save