diff --git a/app/models/case_log.rb b/app/models/case_log.rb index aee84fd03..99285ca3f 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -57,10 +57,15 @@ class CaseLogValidator < ActiveModel::Validator EMPLOYED_STATUSES = ["Full-time - 30 hours or more", "Part-time - Less than 30 hours"].freeze def validate_net_income_uc_proportion(record) - if EMPLOYED_STATUSES.include?(record.tenant_economic_status) && 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 person works part or full time" + (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 - (2..8).any? { |n| check_partner_net_income_uc_proportion(n, record) } end def validate_household_pregnancy(record) @@ -88,14 +93,6 @@ class CaseLogValidator < ActiveModel::Validator private - def check_partner_net_income_uc_proportion(person_num, record) - economic_status = record["person_#{person_num}_economic_status"] - relationship = record["person_#{person_num}_relationship"] - if EMPLOYED_STATUSES.include?(economic_status) && relationship == "Partner" && 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 partner works part or full time" - end - end - def women_of_child_bearing_age_in_household(record) (1..8).any? do |n| next if record["person_#{n}_gender"].nil? || record["person_#{n}_age"].nil? diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index e658da607..ed99d51cf 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -121,7 +121,7 @@ "header": "", "description": "", "questions": { - "tenant_economic_status": { + "person_1_economic_status": { "check_answer_label": "Work", "header": "Which of these best describes the tenant's working situation?", "hint_text": "", diff --git a/db/migrate/20211027091521_rename_person1_fields.rb b/db/migrate/20211027091521_rename_person1_fields.rb new file mode 100644 index 000000000..a9b807e36 --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index 2d4f30da1..8d2405443 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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 enable_extension "plpgsql" @@ -26,7 +26,7 @@ ActiveRecord::Schema.define(version: 2021_10_26_123542) do t.string "tenant_nationality" t.string "previous_housing_situation" t.string "armed_forces" - t.string "tenant_economic_status" + t.string "person_1_economic_status" t.integer "household_number_of_other_members" t.string "person_2_relationship" t.integer "person_2_age" diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index da3e9b6e1..f50e096fb 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -274,7 +274,7 @@ "tenant_nationality": "UK national resident in UK", "previous_housing_situation": "Private sector tenancy", "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, "person_2_relationship": "Partner", "person_2_age": 32, @@ -459,7 +459,7 @@ "type": "string", "minLength": 1 }, - "tenant_economic_status": { + "person_1_economic_status": { "type": "string", "minLength": 1, "enum": [ @@ -1098,7 +1098,7 @@ "tenant_nationality", "previous_housing_situation", "armed_forces", - "tenant_economic_status", + "person_1_economic_status", "household_number_of_other_members", "person_2_relationship", "person_2_age", @@ -1208,4 +1208,4 @@ }, "securitySchemes": {} } -} \ No newline at end of file +} diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 8a539e91c..541c63970 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -8,7 +8,7 @@ "tenant_nationality": "UK national resident in UK", "previous_housing_situation": "Private sector tenancy", "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, "person_2_relationship": "Partner", "person_2_age": 32, diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 91c60c06a..ae85b2fd1 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -100,13 +100,13 @@ RSpec.describe Form, type: :model do 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", tenant_economic_status: "Full-time - 30 hours or more") + 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", tenant_economic_status: "Part-time - Less than 30 hours") + CaseLog.create!(net_income_uc_proportion: "All", person_1_economic_status: "Part-time - Less than 30 hours") }.to raise_error(ActiveRecord::RecordInvalid) end