Browse Source

rename tenant economic status field

pull/62/head
Kat 4 years ago
parent
commit
8f8d86e729
  1. 19
      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. 6
      docs/api/DLUHC-CORE-Data.v1.json
  6. 2
      spec/fixtures/complete_case_log.json
  7. 4
      spec/models/case_log_spec.rb

19
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 EMPLOYED_STATUSES = ["Full-time - 30 hours or more", "Part-time - Less than 30 hours"].freeze
def validate_net_income_uc_proportion(record) def validate_net_income_uc_proportion(record)
if EMPLOYED_STATUSES.include?(record.tenant_economic_status) && record.net_income_uc_proportion == "All" (1..8).any? do |n|
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" 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
(2..8).any? { |n| check_partner_net_income_uc_proportion(n, record) }
end end
def validate_household_pregnancy(record) def validate_household_pregnancy(record)
@ -88,14 +93,6 @@ class CaseLogValidator < ActiveModel::Validator
private 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) def women_of_child_bearing_age_in_household(record)
(1..8).any? do |n| (1..8).any? do |n|
next if record["person_#{n}_gender"].nil? || record["person_#{n}_age"].nil? next if record["person_#{n}_gender"].nil? || record["person_#{n}_age"].nil?

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"

6
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": [
@ -1098,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,

4
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 context "tenant’s income is from Universal Credit, state pensions or benefits" do
it "Cannot be All if person 1 works full time" do it "Cannot be All if person 1 works full time" do
expect { 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) }.to raise_error(ActiveRecord::RecordInvalid)
end end
it "Cannot be All if person 1 works part time" do it "Cannot be All if person 1 works part time" do
expect { 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) }.to raise_error(ActiveRecord::RecordInvalid)
end end

Loading…
Cancel
Save