Browse Source

Relat data type (#423)

pull/424/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
dec350e6f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/models/case_log.rb
  2. 2
      app/models/validations/financial_validations.rb
  3. 8
      app/models/validations/household_validations.rb
  4. 56
      config/forms/2021_2022.json
  5. 39
      db/migrate/20220325122431_change_relat_to_string.rb
  6. 14
      db/schema.rb
  7. 2
      spec/factories/case_log.rb
  8. 13
      spec/fixtures/complete_case_log.json
  9. 14
      spec/fixtures/exports/case_logs.xml
  10. 8
      spec/fixtures/forms/2021_2022.json
  11. 14
      spec/models/case_log_spec.rb
  12. 4
      spec/models/validations/financial_validations_spec.rb
  13. 18
      spec/models/validations/household_validations_spec.rb

6
app/models/case_log.rb

@ -440,7 +440,7 @@ private
def get_totchild def get_totchild
relationships = [relat2, relat3, relat4, relat5, relat6, relat7, relat8] relationships = [relat2, relat3, relat4, relat5, relat6, relat7, relat8]
relationships.count(1) relationships.count("C")
end end
def get_totadult def get_totadult
@ -448,7 +448,7 @@ private
total + (2..8).count do |i| total + (2..8).count do |i|
age = public_send("age#{i}") age = public_send("age#{i}")
relat = public_send("relat#{i}") relat = public_send("relat#{i}")
!age.nil? && ((age >= 16 && age < 18 && [0, 2].include?(relat)) || age >= 18 && age < 60) !age.nil? && ((age >= 16 && age < 18 && %w[P X].include?(relat)) || age >= 18 && age < 60)
end end
end end
@ -546,7 +546,7 @@ private
end end
def relat_refused? def relat_refused?
[relat2, relat3, relat4, relat5, relat6, relat7, relat8].any?(3) [relat2, relat3, relat4, relat5, relat6, relat7, relat8].any?("R")
end end
def ecstat_refused? def ecstat_refused?

2
app/models/validations/financial_validations.rb

@ -14,7 +14,7 @@ module Validations::FinancialValidations
economic_status = record["ecstat#{n}"] economic_status = record["ecstat#{n}"]
is_employed = EMPLOYED_STATUSES.include?(economic_status) is_employed = EMPLOYED_STATUSES.include?(economic_status)
relationship = record["relat#{n}"] relationship = record["relat#{n}"]
is_partner_or_main = relationship&.zero? || (relationship.nil? && economic_status.present?) is_partner_or_main = relationship == "P" || (relationship.nil? && economic_status.present?)
if is_employed && is_partner_or_main && record.benefits&.zero? if is_employed && is_partner_or_main && record.benefits&.zero?
record.errors.add :benefits, I18n.t("validations.financial.benefits.part_or_full_time") record.errors.add :benefits, I18n.t("validations.financial.benefits.part_or_full_time")
end end

8
app/models/validations/household_validations.rb

@ -188,7 +188,7 @@ private
end end
def validate_partner_count(record) def validate_partner_count(record)
partner_count = (2..8).count { |n| record.public_send("relat#{n}")&.zero? } partner_count = (2..8).count { |n| tenant_is_partner?(record["relat#{n}"]) }
if partner_count > 1 if partner_count > 1
record.errors.add :base, I18n.t("validations.household.relat.one_partner") record.errors.add :base, I18n.t("validations.household.relat.one_partner")
end end
@ -210,7 +210,11 @@ private
economic_status == 10 economic_status == 10
end end
def tenant_is_partner?(relationship)
relationship == "P"
end
def tenant_is_child?(relationship) def tenant_is_child?(relationship)
relationship == 1 relationship == "C"
end end
end end

56
config/forms/2021_2022.json

@ -1626,20 +1626,20 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "P": {
"value": "Partner" "value": "Partner"
}, },
"1": { "C": {
"value": "Child", "value": "Child",
"hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." "hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education."
}, },
"2": { "X": {
"value": "Other" "value": "Other"
}, },
"divider": { "divider": {
"value": true "value": true
}, },
"3": { "R": {
"value": "Person prefers not to say" "value": "Person prefers not to say"
} }
} }
@ -1834,20 +1834,20 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "P": {
"value": "Partner" "value": "Partner"
}, },
"1": { "C": {
"value": "Child", "value": "Child",
"hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." "hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education."
}, },
"2": { "X": {
"value": "Other" "value": "Other"
}, },
"divider": { "divider": {
"value": true "value": true
}, },
"3": { "R": {
"value": "Person prefers not to say" "value": "Person prefers not to say"
} }
} }
@ -2039,20 +2039,20 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "P": {
"value": "Partner" "value": "Partner"
}, },
"1": { "C": {
"value": "Child", "value": "Child",
"hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." "hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education."
}, },
"2": { "X": {
"value": "Other" "value": "Other"
}, },
"divider": { "divider": {
"value": true "value": true
}, },
"3": { "R": {
"value": "Person prefers not to say" "value": "Person prefers not to say"
} }
} }
@ -2241,20 +2241,20 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "P": {
"value": "Partner" "value": "Partner"
}, },
"1": { "C": {
"value": "Child", "value": "Child",
"hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." "hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education."
}, },
"2": { "X": {
"value": "Other" "value": "Other"
}, },
"divider": { "divider": {
"value": true "value": true
}, },
"3": { "R": {
"value": "Person prefers not to say" "value": "Person prefers not to say"
} }
} }
@ -2440,20 +2440,20 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "P": {
"value": "Partner" "value": "Partner"
}, },
"1": { "C": {
"value": "Child", "value": "Child",
"hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." "hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education."
}, },
"2": { "X": {
"value": "Other" "value": "Other"
}, },
"divider": { "divider": {
"value": true "value": true
}, },
"3": { "R": {
"value": "Person prefers not to say" "value": "Person prefers not to say"
} }
} }
@ -2636,20 +2636,20 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "P": {
"value": "Partner" "value": "Partner"
}, },
"1": { "C": {
"value": "Child", "value": "Child",
"hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." "hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education."
}, },
"2": { "X": {
"value": "Other" "value": "Other"
}, },
"divider": { "divider": {
"value": true "value": true
}, },
"3": { "R": {
"value": "Person prefers not to say" "value": "Person prefers not to say"
} }
} }
@ -2829,20 +2829,20 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "P": {
"value": "Partner" "value": "Partner"
}, },
"1": { "C": {
"value": "Child", "value": "Child",
"hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." "hint": "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education."
}, },
"2": { "X": {
"value": "Other" "value": "Other"
}, },
"divider": { "divider": {
"value": true "value": true
}, },
"3": { "R": {
"value": "Person prefers not to say" "value": "Person prefers not to say"
} }
} }

39
db/migrate/20220325122431_change_relat_to_string.rb

@ -0,0 +1,39 @@
class ChangeRelatToString < ActiveRecord::Migration[7.0]
def up
change_table :case_logs, bulk: true do |t|
t.remove :relat2
t.column :relat2, :string
t.remove :relat3
t.column :relat3, :string
t.remove :relat4
t.column :relat4, :string
t.remove :relat5
t.column :relat5, :string
t.remove :relat6
t.column :relat6, :string
t.remove :relat7
t.column :relat7, :string
t.remove :relat8
t.column :relat8, :string
end
end
def down
change_table :case_logs, bulk: true do |t|
t.remove :relat2
t.column :relat2, :integer
t.remove :relat3
t.column :relat3, :integer
t.remove :relat4
t.column :relat4, :integer
t.remove :relat5
t.column :relat5, :integer
t.remove :relat6
t.column :relat6, :integer
t.remove :relat7
t.column :relat7, :integer
t.remove :relat8
t.column :relat8, :integer
end
end
end

14
db/schema.rb

@ -208,13 +208,6 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.integer "details_known_6" t.integer "details_known_6"
t.integer "details_known_7" t.integer "details_known_7"
t.integer "details_known_8" t.integer "details_known_8"
t.integer "relat2"
t.integer "relat3"
t.integer "relat4"
t.integer "relat5"
t.integer "relat6"
t.integer "relat7"
t.integer "relat8"
t.integer "rent_type" t.integer "rent_type"
t.integer "has_benefits" t.integer "has_benefits"
t.integer "renewal" t.integer "renewal"
@ -230,6 +223,13 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.integer "vmonth" t.integer "vmonth"
t.integer "vyear" t.integer "vyear"
t.decimal "wchchrg", precision: 10, scale: 2 t.decimal "wchchrg", precision: 10, scale: 2
t.string "relat2"
t.string "relat3"
t.string "relat4"
t.string "relat5"
t.string "relat6"
t.string "relat7"
t.string "relat8"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"
end end

2
spec/factories/case_log.rb

@ -43,7 +43,7 @@ FactoryBot.define do
ecstat1 { 0 } ecstat1 { 0 }
other_hhmemb { 1 } other_hhmemb { 1 }
hhmemb { 2 } hhmemb { 2 }
relat2 { 0 } relat2 { "P" }
age2 { 32 } age2 { 32 }
sex2 { "M" } sex2 { "M" }
ecstat2 { 6 } ecstat2 { 6 }

13
spec/fixtures/complete_case_log.json vendored

@ -11,31 +11,30 @@
"ecstat1": 1, "ecstat1": 1,
"other_hhmemb": 7, "other_hhmemb": 7,
"hhmemb": 8, "hhmemb": 8,
"relat2": 0, "relat2": "P",
"age2": 32, "age2": 32,
"sex2": "M", "sex2": "M",
"ecstat2": 6, "ecstat2": 6,
"relat3": 1, "relat3": "C",
"age3": 12, "age3": 12,
"sex3": "M", "sex3": "M",
"ecstat3": 9, "ecstat3": 9,
"relat4": 1, "relat4": "C",
"age4": 12, "age4": 12,
"sex4": "F", "sex4": "F",
"ecstat4": 9, "ecstat4": 9,
"relat5": 1, "relat5": "C",
"age5": 10, "age5": 10,
"sex5": "X", "sex5": "X",
"ecstat5": 9, "ecstat5": 9,
"relat6": 1, "relat6": "C",
"age6": 5, "age6": 5,
"sex6": "R", "sex6": "R",
"ecstat6": 9, "ecstat6": 9,
"relat7": 1,
"age7": 5, "age7": 5,
"sex7": "R", "sex7": "R",
"ecstat7": 9, "ecstat7": 9,
"relat8": 1, "relat8": "C",
"age8": 2, "age8": 2,
"sex8": "R", "sex8": "R",
"ecstat8": 9, "ecstat8": 9,

14
spec/fixtures/exports/case_logs.xml vendored

@ -150,13 +150,6 @@
<is_previous_la_inferred>false</is_previous_la_inferred> <is_previous_la_inferred>false</is_previous_la_inferred>
<ethnic_other/> <ethnic_other/>
<letting_allocation_unknown/> <letting_allocation_unknown/>
<relat2>0</relat2>
<relat3/>
<relat4/>
<relat5/>
<relat6/>
<relat7/>
<relat8/>
<rent_type>1</rent_type> <rent_type>1</rent_type>
<has_benefits>1</has_benefits> <has_benefits>1</has_benefits>
<renewal>0</renewal> <renewal>0</renewal>
@ -172,5 +165,12 @@
<vmonth>11</vmonth> <vmonth>11</vmonth>
<vyear>2019</vyear> <vyear>2019</vyear>
<wchchrg/> <wchchrg/>
<relat2>P</relat2>
<relat3/>
<relat4/>
<relat5/>
<relat6/>
<relat7/>
<relat8/>
</form> </form>
</forms> </forms>

8
spec/fixtures/forms/2021_2022.json vendored

@ -137,10 +137,10 @@
"header": "What is person 2’s relationship to lead tenant", "header": "What is person 2’s relationship to lead tenant",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": { "X": {
"value": "Other" "value": "Other"
}, },
"1": { "R": {
"value": "Prefer not to say" "value": "Prefer not to say"
} }
} }
@ -775,7 +775,7 @@
"width": 4 "width": 4
} }
}, },
"depends_on": [{"period": 3}] "depends_on": [{"period": 3}]
}, },
"care_home_charge_bi_weekly": { "care_home_charge_bi_weekly": {
"questions": { "questions": {
@ -789,7 +789,7 @@
"width": 4 "width": 4
} }
}, },
"depends_on": [{"period": 2}] "depends_on": [{"period": 2}]
} }
} }
} }

14
spec/models/case_log_spec.rb

@ -1298,12 +1298,12 @@ RSpec.describe CaseLog do
managing_organisation: organisation, managing_organisation: organisation,
owning_organisation: organisation, owning_organisation: organisation,
other_hhmemb: 4, other_hhmemb: 4,
relat2: 1, relat2: "C",
relat3: 1, relat3: "C",
relat4: 2, relat4: "X",
relat5: 1, relat5: "C",
relat7: 2, relat7: "X",
relat8: 2, relat8: "X",
age1: 22, age1: 22,
age2: 14, age2: 14,
age4: 60, age4: 60,
@ -1385,7 +1385,7 @@ RSpec.describe CaseLog do
owning_organisation: organisation, owning_organisation: organisation,
age1_known: 1, age1_known: 1,
sex1: "R", sex1: "R",
relat2: 3, relat2: "R",
ecstat1: 10, ecstat1: 10,
}) })
end end

4
spec/models/validations/financial_validations_spec.rb

@ -50,7 +50,7 @@ RSpec.describe Validations::FinancialValidations do
it "validates that the tenant's partner is not in full time employment" do it "validates that the tenant's partner is not in full time employment" do
record.benefits = 0 record.benefits = 0
record.ecstat2 = 0 record.ecstat2 = 0
record.relat2 = 0 record.relat2 = "P"
financial_validator.validate_net_income_uc_proportion(record) financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to include(match I18n.t("validations.financial.benefits.part_or_full_time")) expect(record.errors["benefits"]).to include(match I18n.t("validations.financial.benefits.part_or_full_time"))
end end
@ -58,7 +58,7 @@ RSpec.describe Validations::FinancialValidations do
it "expects that the tenant's partner is not in full-time or part-time employment" do it "expects that the tenant's partner is not in full-time or part-time employment" do
record.benefits = 0 record.benefits = 0
record.ecstat2 = 4 record.ecstat2 = 4
record.relat2 = 0 record.relat2 = "P"
financial_validator.validate_net_income_uc_proportion(record) financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to be_empty expect(record.errors["benefits"]).to be_empty
end end

18
spec/models/validations/household_validations_spec.rb

@ -276,15 +276,15 @@ RSpec.describe Validations::HouseholdValidations do
describe "household member validations" do describe "household member validations" do
it "validates that only 1 partner exists" do it "validates that only 1 partner exists" do
record.relat2 = 0 record.relat2 = "P"
record.relat3 = 0 record.relat3 = "P"
household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record)
expect(record.errors["base"]) expect(record.errors["base"])
.to include(match I18n.t("validations.household.relat.one_partner")) .to include(match I18n.t("validations.household.relat.one_partner"))
end end
it "expects that a tenant can have a partner" do it "expects that a tenant can have a partner" do
record.relat3 = 0 record.relat3 = "P"
household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record)
expect(record.errors["base"]).to be_empty expect(record.errors["base"]).to be_empty
end end
@ -292,7 +292,7 @@ RSpec.describe Validations::HouseholdValidations do
context "when the household contains a person under 16" do context "when the household contains a person under 16" do
it "validates that person must be a child of the tenant" do it "validates that person must be a child of the tenant" do
record.age2 = 14 record.age2 = 14
record.relat2 = 0 record.relat2 = "P"
household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record)
expect(record.errors["relat2"]) expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.child_under_16", person_num: 2)) .to include(match I18n.t("validations.household.relat.child_under_16", person_num: 2))
@ -302,7 +302,7 @@ RSpec.describe Validations::HouseholdValidations do
it "expects that person is a child of the tenant" do it "expects that person is a child of the tenant" do
record.age2 = 14 record.age2 = 14
record.relat2 = 1 record.relat2 = "C"
household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record)
expect(record.errors["relat2"]).to be_empty expect(record.errors["relat2"]).to be_empty
expect(record.errors["age2"]).to be_empty expect(record.errors["age2"]).to be_empty
@ -328,7 +328,7 @@ RSpec.describe Validations::HouseholdValidations do
it "validates that a person with economic status 'child' must be under 16" do it "validates that a person with economic status 'child' must be under 16" do
record.age2 = 21 record.age2 = 21
record.relat2 = 1 record.relat2 = "C"
record.ecstat2 = 9 record.ecstat2 = 9
household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record)
expect(record.errors["ecstat2"]) expect(record.errors["ecstat2"])
@ -341,7 +341,7 @@ RSpec.describe Validations::HouseholdValidations do
context "when the household contains a tenant's child between the ages of 16 and 19" do context "when the household contains a tenant's child between the ages of 16 and 19" do
it "validates that person's economic status must be full time student or refused" do it "validates that person's economic status must be full time student or refused" do
record.age2 = 17 record.age2 = 17
record.relat2 = 1 record.relat2 = "C"
record.ecstat2 = 1 record.ecstat2 = 1
household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record)
expect(record.errors["ecstat2"]) expect(record.errors["ecstat2"])
@ -354,7 +354,7 @@ RSpec.describe Validations::HouseholdValidations do
it "expects that person can be a full time student" do it "expects that person can be a full time student" do
record.age2 = 17 record.age2 = 17
record.relat2 = 1 record.relat2 = "C"
record.ecstat2 = 7 record.ecstat2 = 7
household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record)
expect(record.errors["ecstat2"]).to be_empty expect(record.errors["ecstat2"]).to be_empty
@ -364,7 +364,7 @@ RSpec.describe Validations::HouseholdValidations do
it "expects that person can refuse to share their work status" do it "expects that person can refuse to share their work status" do
record.age2 = 17 record.age2 = 17
record.relat2 = 1 record.relat2 = "C"
record.ecstat2 = 10 record.ecstat2 = 10
household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record)
expect(record.errors["ecstat2"]).to be_empty expect(record.errors["ecstat2"]).to be_empty

Loading…
Cancel
Save