Browse Source

Gender chars instead of ints

pull/321/head
baarkerlounger 3 years ago
parent
commit
be2cf2561d
  1. 6
      app/models/validations/household_validations.rb
  2. 64
      config/forms/2021_2022.json
  3. 32
      db/migrate/20220221181805_integer_fields.rb
  4. 16
      db/schema.rb
  5. 6
      spec/factories/case_log.rb
  6. 8
      spec/features/form/check_answers_page_spec.rb
  7. 2
      spec/features/form/page_routing_spec.rb
  8. 4
      spec/features/form/saving_data_spec.rb
  9. 16
      spec/fixtures/complete_case_log.json
  10. 4
      spec/fixtures/exports/case_logs.xml
  11. 18
      spec/fixtures/forms/2021_2022.json
  12. 2
      spec/models/case_log_spec.rb
  13. 20
      spec/models/validations/household_validations_spec.rb

6
app/models/validations/household_validations.rb

@ -101,7 +101,7 @@ private
(1..8).any? do |n|
next if record["sex#{n}"].nil? || record["age#{n}"].nil?
(record["sex#{n}"])&.zero? && record["age#{n}"] >= 16 && record["age#{n}"] <= 50
(record["sex#{n}"]) == "F" && record["age#{n}"] >= 16 && record["age#{n}"] <= 50
end
end
@ -160,10 +160,10 @@ private
economic_status = record.public_send("ecstat#{person_num}")
return unless age && economic_status && gender
if gender == 1 && economic_status == 4 && age < 65
if gender == "M" && economic_status == 4 && age < 65
record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_male")
end
if gender && gender.zero? && economic_status == 4 && age < 60
if gender == "F" && economic_status == 4 && age < 60
record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_female")
end
end

64
config/forms/2021_2022.json

@ -1136,16 +1136,16 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": {
"F": {
"value": "Female"
},
"1": {
"M": {
"value": "Male"
},
"2": {
"X": {
"value": "Non-binary"
},
"3": {
"R": {
"value": "Prefer not to say"
}
}
@ -1427,16 +1427,16 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": {
"F": {
"value": "Female"
},
"1": {
"M": {
"value": "Male"
},
"2": {
"X": {
"value": "Non-binary"
},
"3": {
"R": {
"value": "Prefer not to say"
}
}
@ -1518,16 +1518,16 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": {
"F": {
"value": "Female"
},
"1": {
"M": {
"value": "Male"
},
"2": {
"X": {
"value": "Non-binary"
},
"3": {
"R": {
"value": "Prefer not to say"
}
}
@ -1609,16 +1609,16 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": {
"F": {
"value": "Female"
},
"1": {
"M": {
"value": "Male"
},
"2": {
"X": {
"value": "Non-binary"
},
"3": {
"R": {
"value": "Prefer not to say"
}
}
@ -1700,16 +1700,16 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": {
"F": {
"value": "Female"
},
"1": {
"M": {
"value": "Male"
},
"2": {
"X": {
"value": "Non-binary"
},
"3": {
"R": {
"value": "Prefer not to say"
}
}
@ -1791,16 +1791,16 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": {
"F": {
"value": "Female"
},
"1": {
"M": {
"value": "Male"
},
"2": {
"X": {
"value": "Non-binary"
},
"3": {
"R": {
"value": "Prefer not to say"
}
}
@ -1881,16 +1881,16 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": {
"F": {
"value": "Female"
},
"1": {
"M": {
"value": "Male"
},
"2": {
"X": {
"value": "Non-binary"
},
"3": {
"R": {
"value": "Prefer not to say"
}
}
@ -1971,16 +1971,16 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": {
"F": {
"value": "Female"
},
"1": {
"M": {
"value": "Male"
},
"2": {
"X": {
"value": "Non-binary"
},
"3": {
"R": {
"value": "Prefer not to say"
}
}

32
db/migrate/20220221181805_integer_fields.rb

@ -1,22 +1,6 @@
class IntegerFields < ActiveRecord::Migration[7.0]
def up
change_table :case_logs, bulk: true do |t|
t.remove :sex1
t.column :sex1, :integer
t.remove :sex2
t.column :sex2, :integer
t.remove :sex3
t.column :sex3, :integer
t.remove :sex4
t.column :sex4, :integer
t.remove :sex5
t.column :sex5, :integer
t.remove :sex6
t.column :sex6, :integer
t.remove :sex7
t.column :sex7, :integer
t.remove :sex8
t.column :sex8, :integer
t.remove :relat2
t.column :relat2, :integer
t.remove :relat3
@ -42,22 +26,6 @@ class IntegerFields < ActiveRecord::Migration[7.0]
def down
change_table :case_logs, bulk: true do |t|
t.remove :sex1
t.column :sex1, :string
t.remove :sex2
t.column :sex2, :string
t.remove :sex3
t.column :sex3, :string
t.remove :sex4
t.column :sex4, :string
t.remove :sex5
t.column :sex5, :string
t.remove :sex6
t.column :sex6, :string
t.remove :sex7
t.column :sex7, :string
t.remove :sex8
t.column :sex8, :string
t.remove :relat2
t.column :relat2, :string
t.remove :relat3

16
db/schema.rb

@ -179,14 +179,14 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.boolean "is_previous_la_inferred"
t.integer "letting_allocation_unknown"
t.integer "renttype"
t.integer "sex1"
t.integer "sex2"
t.integer "sex3"
t.integer "sex4"
t.integer "sex5"
t.integer "sex6"
t.integer "sex7"
t.integer "sex8"
t.string "sex1"
t.string "sex2"
t.string "sex3"
t.string "sex4"
t.string "sex5"
t.string "sex6"
t.string "sex7"
t.string "sex8"
t.integer "relat2"
t.integer "relat3"
t.integer "relat4"

6
spec/factories/case_log.rb

@ -25,7 +25,7 @@ FactoryBot.define do
trait :conditional_section_complete do
tenant_code { "TH356" }
age1 { 34 }
sex1 { 1 }
sex1 { "M" }
ethnic { 2 }
national { 4 }
ecstat1 { 2 }
@ -36,7 +36,7 @@ FactoryBot.define do
tenant_code { "BZ737" }
postcode { "NW1 7TY" }
age1 { 35 }
sex1 { 0 }
sex1 { "F" }
ethnic { 2 }
national { 4 }
prevten { 6 }
@ -45,7 +45,7 @@ FactoryBot.define do
hhmemb { 2 }
relat2 { 0 }
age2 { 32 }
sex2 { 1 }
sex2 { "M" }
ecstat2 { 5 }
homeless { 1 }
underoccupation_benefitcap { 0 }

8
spec/features/form/check_answers_page_spec.rb

@ -61,7 +61,7 @@ RSpec.describe "Form Check Answers Page" do
it "displays answers given by the user for the question in the subsection" do
fill_in_number_question(empty_case_log.id, "age1", 28, "person-1-age")
choose("case-log-sex1-2-field")
choose("case-log-sex1-x-field")
click_button("Save and continue")
visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers")
expect(page).to have_content("28")
@ -136,7 +136,7 @@ RSpec.describe "Form Check Answers Page" do
managing_organisation: user.organisation,
tenant_code: "123",
age1: 35,
sex1: 1,
sex1: "M",
other_hhmemb: 0,
)
end
@ -149,7 +149,7 @@ RSpec.describe "Form Check Answers Page" do
managing_organisation: user.organisation,
tenant_code: "123",
age1: 35,
sex1: 1,
sex1: "M",
other_hhmemb: 0,
armedforces: 3,
illness: 0,
@ -164,7 +164,7 @@ RSpec.describe "Form Check Answers Page" do
managing_organisation: user.organisation,
tenant_code: "123",
age1: 35,
sex1: 1,
sex1: "M",
other_hhmemb: 0,
armedforces: 3,
illness: 0,

2
spec/features/form/page_routing_spec.rb

@ -36,7 +36,7 @@ RSpec.describe "Form Page Routing" do
it "can route based on multiple conditions", js: true do
visit("/logs/#{id}/person-1-gender")
choose("case-log-sex1-0-field", allow_label_click: true)
choose("case-log-sex1-f-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/logs/#{id}/household-number-of-other-members")
visit("/logs/#{id}/conditional-question")

4
spec/features/form/saving_data_spec.rb

@ -25,7 +25,7 @@ RSpec.describe "Form Saving Data" do
{
tenant_code: { type: "text", answer: "BZ737", path: "tenant_code" },
age1: { type: "numeric", answer: 25, path: "person_1_age" },
sex1: { type: "radio", answer: { 0 => "Female" }, path: "person_1_gender" },
sex1: { type: "radio", answer: { "F" => "Female" }, path: "person_1_gender" },
other_hhmemb: { type: "numeric", answer: 2, path: "household_number_of_other_members" },
}
end
@ -45,7 +45,7 @@ RSpec.describe "Form Saving Data" do
when "text"
fill_in("case-log-#{question.to_s.dasherize}-field", with: answer)
when "radio"
choose("case-log-#{question.to_s.dasherize}-#{hsh[:answer].keys.first}-field")
choose("case-log-#{question.to_s.dasherize}-#{hsh[:answer].keys.first.downcase}-field")
else
fill_in("case-log-#{question.to_s.dasherize}-field", with: answer)
end

16
spec/fixtures/complete_case_log.json vendored

@ -2,7 +2,7 @@
"case_log": {
"tenant_code": "T657",
"age1": 35,
"sex1": 0,
"sex1": "F",
"ethnic": 0,
"national": 0,
"prevten": 6,
@ -13,31 +13,31 @@
"hhmemb": 8,
"relat2": 0,
"age2": 32,
"sex2": 1,
"sex2": "M",
"ecstat2": 5,
"relat3": 1,
"age3": 12,
"sex3": 1,
"sex3": "M",
"ecstat3": 8,
"relat4": 1,
"age4": 12,
"sex4": 0,
"sex4": "F",
"ecstat4": 8,
"relat5": 1,
"age5": 10,
"sex5": 2,
"sex5": "X",
"ecstat5": 8,
"relat6": 1,
"age6": 5,
"sex6": 3,
"sex6": "R",
"ecstat6": 8,
"relat7": 1,
"age7": 5,
"sex7": 3,
"sex7": "R",
"ecstat7": 8,
"relat8": 1,
"age8": 2,
"sex8": 3,
"sex8": "R",
"ecstat8": 8,
"homeless": 2,
"reason": 1,

4
spec/fixtures/exports/case_logs.xml vendored

@ -141,8 +141,8 @@
<is_previous_la_inferred>false</is_previous_la_inferred>
<letting_allocation_unknown/>
<renttype>2</renttype>
<sex1>0</sex1>
<sex2>1</sex2>
<sex1>F</sex1>
<sex2>M</sex2>
<sex3/>
<sex4/>
<sex5/>

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

@ -48,16 +48,16 @@
"header": "Which of these best describes the tenant’s gender identity?",
"type": "radio",
"answer_options": {
"0": {
"F": {
"value": "Female"
},
"1": {
"M": {
"value": "Male"
},
"2": {
"X": {
"value": "Non-binary"
},
"3": {
"R": {
"value": "Prefer not to say"
}
}
@ -109,16 +109,16 @@
"header": "Which of these best describes person 2’s gender identity?",
"type": "radio",
"answer_options": {
"0": {
"F": {
"value": "Female"
},
"1": {
"M": {
"value": "Male"
},
"2": {
"X": {
"value": "Non-binary"
},
"3": {
"R": {
"value": "Prefer not to say"
}
}
@ -438,7 +438,7 @@
}
}
},
"depends_on": [{ "preg_occ": 1, "sex1": 1 }]
"depends_on": [{ "preg_occ": 1, "sex1": "M" }]
}
}
}

2
spec/models/case_log_spec.rb

@ -573,7 +573,7 @@ RSpec.describe CaseLog do
end
it "does clear the value for answers that do not apply for invalidated page" do
case_log.update!({ wchair: 1, sex2: 0, age2: 33 })
case_log.update!({ wchair: 1, sex2: "F", age2: 33 })
case_log.update!({ cbl: 0 })
case_log.update!({ preg_occ: 0 })

20
spec/models/validations/household_validations_spec.rb

@ -115,7 +115,7 @@ RSpec.describe Validations::HouseholdValidations do
context "when there are no female tenants" do
it "validates that pregnancy cannot be yes" do
record.preg_occ = 0
record.sex1 = 1
record.sex1 = "M"
household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"])
.to include(match I18n.t("validations.household.preg_occ.no_female"))
@ -123,7 +123,7 @@ RSpec.describe Validations::HouseholdValidations do
it "validates that pregnancy cannot be prefer not to say" do
record.preg_occ = 2
record.sex1 = 1
record.sex1 = "M"
household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"])
.to include(match I18n.t("validations.household.preg_occ.no_female"))
@ -134,7 +134,7 @@ RSpec.describe Validations::HouseholdValidations do
context "but they are older than 50" do
it "validates that pregnancy cannot be yes" do
record.preg_occ = 0
record.sex1 = 0
record.sex1 = "F"
record.age1 = 51
household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"])
@ -145,7 +145,7 @@ RSpec.describe Validations::HouseholdValidations do
context "and they are the main tenant and under 51" do
it "pregnancy can be yes" do
record.preg_occ = 0
record.sex1 = 0
record.sex1 = "F"
record.age1 = 32
household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"]).to be_empty
@ -155,9 +155,9 @@ RSpec.describe Validations::HouseholdValidations do
context "and they are another household member and under 51" do
it "pregnancy can be yes" do
record.preg_occ = 0
record.sex1 = 1
record.sex1 = "M"
record.age1 = 25
record.sex3 = 0
record.sex3 = "F"
record.age3 = 32
household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"]).to be_empty
@ -400,7 +400,7 @@ RSpec.describe Validations::HouseholdValidations do
context "when the household contains a retired male" do
it "validates that person must be over 65" do
record.age2 = 64
record.sex2 = 1
record.sex2 = "M"
record.ecstat2 = 4
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["age2"])
@ -409,7 +409,7 @@ RSpec.describe Validations::HouseholdValidations do
it "expects that person is over 65" do
record.age2 = 66
record.sex2 = 1
record.sex2 = "M"
record.ecstat2 = 4
household_validator.validate_household_number_of_other_members(record)
household_validator.validate_household_number_of_other_members(record)
@ -420,7 +420,7 @@ RSpec.describe Validations::HouseholdValidations do
context "when the household contains a retired female" do
it "validates that person must be over 60" do
record.age2 = 59
record.sex2 = 0
record.sex2 = "F"
record.ecstat2 = 4
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["age2"])
@ -429,7 +429,7 @@ RSpec.describe Validations::HouseholdValidations do
it "expects that person is over 60" do
record.age2 = 61
record.sex2 = 0
record.sex2 = "F"
record.ecstat2 = 4
household_validator.validate_household_number_of_other_members(record)
household_validator.validate_household_number_of_other_members(record)

Loading…
Cancel
Save