From cf46ae46fe64490f63129b65b8e57f584de764f1 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Fri, 24 Mar 2023 14:18:34 +0000
Subject: [PATCH 1/4] CLDC-2131 Update pregnancy validation (#1458)
* Remove hard pregnancy validation and update soft validation
* Remove validate_pregnancy references
* Don't care about the age in gender validation
---
.../validations/household_validations.rb | 6 --
app/models/validations/soft_validations.rb | 10 ++-
config/locales/en.yml | 4 +-
spec/features/form/page_routing_spec.rb | 1 -
.../validations/household_validations_spec.rb | 67 -------------------
.../validations/soft_validations_spec.rb | 11 ++-
spec/requests/form_controller_spec.rb | 4 --
7 files changed, 18 insertions(+), 85 deletions(-)
diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb
index 0b871fce0..e56a16783 100644
--- a/app/models/validations/household_validations.rb
+++ b/app/models/validations/household_validations.rb
@@ -35,12 +35,6 @@ module Validations::HouseholdValidations
end
end
- def validate_pregnancy(record)
- if (record.has_pregnancy? || record.pregnancy_refused?) && women_in_household(record) && !women_of_child_bearing_age_in_household(record)
- record.errors.add :preg_occ, I18n.t("validations.household.preg_occ.no_female")
- end
- end
-
def validate_household_number_of_other_members(record)
(2..8).each do |n|
validate_person_age_matches_economic_status(record, n)
diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb
index fc2c469ca..fbc5ab3b9 100644
--- a/app/models/validations/soft_validations.rb
+++ b/app/models/validations/soft_validations.rb
@@ -53,11 +53,11 @@ module Validations::SoftValidations
end
def no_females_in_a_pregnant_household?
- !females_in_the_household? && all_tenants_age_and_gender_information_completed? && preg_occ == 1
+ !females_in_the_household? && all_tenants_gender_information_completed? && preg_occ == 1
end
def female_in_pregnant_household_in_soft_validation_range?
- all_tenants_age_and_gender_information_completed? && (females_in_age_range(11, 15) || females_in_age_range(51, 65)) && !females_in_age_range(16, 50) && preg_occ == 1
+ all_tenants_age_and_gender_information_completed? && females_in_the_household? && !females_in_age_range(16, 50) && preg_occ == 1
end
def all_tenants_age_and_gender_information_completed?
@@ -66,6 +66,12 @@ module Validations::SoftValidations
end
end
+ def all_tenants_gender_information_completed?
+ (1..hhmemb).all? do |n|
+ public_send("sex#{n}").present? && details_known_or_lead_tenant?(n)
+ end
+ end
+
TWO_YEARS_IN_DAYS = 730
TEN_YEARS_IN_DAYS = 3650
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a7a5e5400..7e514b17f 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -335,8 +335,6 @@ en:
leftreg:
question_required: "Tell us whether the person is still serving in the UK armed forces as you told us they’re a current or former regular"
question_not_required: "You cannot answer whether the person is still serving in the UK armed forces as you told us they’re not a current or former regular"
- preg_occ:
- no_female: "Enter ‘no’ as there are no female tenants aged 11-65 in the household"
age:
retired_male: "A male tenant who is retired must be 65 or over"
retired_female: "A female tenant who is retired must be 60 or over"
@@ -516,7 +514,7 @@ en:
pregnancy:
title: "You told us somebody in the household is pregnant"
no_females: "You also told us there are no female tenants living at the property."
- females_not_in_soft_age_range: "You also told us that any female tenants living at the property are in the following age ranges:
"
+ females_not_in_soft_age_range: "You also told us that any female tenants living at the property are in the following age ranges:- under 16 years old
- over 50 years old
"
major_repairs_date:
title_text: "You told us the time between the start of the tenancy and the major repairs completion date is more than 2 years"
void_date:
diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb
index 312e0752b..0ba8ece6e 100644
--- a/spec/features/form/page_routing_spec.rb
+++ b/spec/features/form/page_routing_spec.rb
@@ -16,7 +16,6 @@ RSpec.describe "Form Page Routing" do
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
- allow(validator).to receive(:validate_pregnancy).and_return(true)
sign_in user
end
diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb
index daa3feef1..e1837a43d 100644
--- a/spec/models/validations/household_validations_spec.rb
+++ b/spec/models/validations/household_validations_spec.rb
@@ -60,73 +60,6 @@ RSpec.describe Validations::HouseholdValidations do
end
end
- describe "pregnancy validations" do
- context "when there are no female tenants" do
- it "validates that pregnancy can be yes" do
- record.preg_occ = 1
- record.sex1 = "M"
- household_validator.validate_pregnancy(record)
- expect(record.errors["preg_occ"]).to be_empty
- end
-
- it "validates that pregnancy can be prefer not to say" do
- record.preg_occ = 3
- record.sex1 = "M"
- household_validator.validate_pregnancy(record)
- expect(record.errors["preg_occ"]).to be_empty
- end
- end
-
- context "when there are female tenants" do
- context "but they are older than 65" do
- before { record.assign_attributes(sex1: "F", age1: 66, preg_occ: 1) }
-
- it "validates that pregnancy cannot be yes" do
- household_validator.validate_pregnancy(record)
- expect(record.errors["preg_occ"])
- .to include(match I18n.t("validations.household.preg_occ.no_female"))
- end
- end
-
- context "and they are the lead tenant and under 65" do
- before { record.assign_attributes(sex1: "F", age1: 64, preg_occ: 1) }
-
- it "allows pregnancy to be set to yes" do
- household_validator.validate_pregnancy(record)
- expect(record.errors["preg_occ"]).to be_empty
- end
- end
-
- context "and they are another household member and under 51" do
- before { record.assign_attributes(sex1: "M", age1: 25, sex3: "F", age3: 64, preg_occ: 1) }
-
- it "allows pregnancy to be set to yes" do
- household_validator.validate_pregnancy(record)
- expect(record.errors["preg_occ"]).to be_empty
- end
- end
-
- context "and they are another household member and under 11" do
- before { record.assign_attributes(sex1: "M", age1: 25, sex3: "F", age3: 10, preg_occ: 1) }
-
- it "validates that pregnancy cannot be yes" do
- household_validator.validate_pregnancy(record)
- expect(record.errors["preg_occ"])
- .to include(match I18n.t("validations.household.preg_occ.no_female"))
- end
- end
-
- context "and one tenant's age is unknown" do
- before { record.assign_attributes(sex1: "F", age1: nil, age1_known: 1, preg_occ: 1) }
-
- it "allows pregnancy to be set to yes" do
- household_validator.validate_pregnancy(record)
- expect(record.errors["preg_occ"]).to be_empty
- end
- end
- end
- end
-
describe "reason for leaving last settled home validations" do
let(:field) { "validations.other_field_not_required" }
let(:main_field_label) { "reason" }
diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb
index b71d91a62..d355f2fbd 100644
--- a/spec/models/validations/soft_validations_spec.rb
+++ b/spec/models/validations/soft_validations_spec.rb
@@ -175,14 +175,21 @@ RSpec.describe Validations::SoftValidations do
end
end
- context "when female tenants are in 11-16 age range" do
+ context "when there are no female tenants and age of other tenants is unknown" do
+ it "shows the interruption screen" do
+ record.update!(sex1: "M", preg_occ: 1, hhmemb: 1, age1_known: 1)
+ expect(record.no_females_in_a_pregnant_household?).to be true
+ end
+ end
+
+ context "when female tenants are under 16" do
it "shows the interruption screen" do
record.update!(age2: 14, sex2: "F", preg_occ: 1, hhmemb: 2, details_known_2: 0, age2_known: 0, age1: 18, sex1: "M", age1_known: 0)
expect(record.female_in_pregnant_household_in_soft_validation_range?).to be true
end
end
- context "when female tenants are in 50-65 age range" do
+ context "when female tenants are over 50" do
it "shows the interruption screen" do
record.update!(age1: 54, sex1: "F", preg_occ: 1, hhmemb: 1, age1_known: 0)
expect(record.female_in_pregnant_household_in_soft_validation_range?).to be true
diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb
index 9dce39af2..9787ce097 100644
--- a/spec/requests/form_controller_spec.rb
+++ b/spec/requests/form_controller_spec.rb
@@ -632,10 +632,6 @@ RSpec.describe FormController, type: :request do
}
end
- before do
- allow(validator).to receive(:validate_pregnancy).and_return(true)
- end
-
it "routes to the appropriate conditional page based on the question answer of the current page" do
post "/lettings-logs/#{lettings_log.id}/form", params: lettings_log_form_conditional_question_yes_params
expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}/conditional-question-yes-page")
From 8d9c577e6979e93f9711b0f4fd384c79d1d5b2ff Mon Sep 17 00:00:00 2001
From: Phil Lee
Date: Fri, 24 Mar 2023 14:32:57 +0000
Subject: [PATCH 2/4] disable start date validation for staging (#1466)
---
config/initializers/feature_toggle.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/config/initializers/feature_toggle.rb b/config/initializers/feature_toggle.rb
index 6c889bcc5..de1c11fbd 100644
--- a/config/initializers/feature_toggle.rb
+++ b/config/initializers/feature_toggle.rb
@@ -5,7 +5,7 @@ class FeatureToggle
end
def self.startdate_collection_window_validation_enabled?
- Rails.env.production? || Rails.env.test? || Rails.env.staging?
+ Rails.env.production? || Rails.env.test?
end
def self.startdate_two_week_validation_enabled?
From ea810beab1c3b8ce73567fd74f5bb6f70ab7e21b Mon Sep 17 00:00:00 2001
From: Jack <113976590+bibblobcode@users.noreply.github.com>
Date: Fri, 24 Mar 2023 14:56:57 +0000
Subject: [PATCH 3/4] Address UPRN PO review (#1467)
* Fix question number rendering
* Update title copy
---
app/models/form/lettings/pages/address.rb | 2 +-
app/models/form/lettings/questions/address_line1.rb | 2 +-
app/models/form/lettings/questions/uprn_known.rb | 2 +-
app/models/form/sales/pages/address.rb | 2 +-
app/models/form/sales/questions/address_line1.rb | 2 +-
app/models/form/sales/questions/uprn_known.rb | 2 +-
spec/models/form/lettings/pages/address_spec.rb | 2 +-
spec/models/form/lettings/questions/address_line1_spec.rb | 4 ++--
spec/models/form/lettings/questions/uprn_known_spec.rb | 2 +-
spec/models/form/sales/pages/address_spec.rb | 2 +-
spec/models/form/sales/questions/address_line1_spec.rb | 4 ++--
spec/models/form/sales/questions/uprn_known_spec.rb | 2 +-
12 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/app/models/form/lettings/pages/address.rb b/app/models/form/lettings/pages/address.rb
index 6f88bad0d..cf6f73036 100644
--- a/app/models/form/lettings/pages/address.rb
+++ b/app/models/form/lettings/pages/address.rb
@@ -2,7 +2,7 @@ class Form::Lettings::Pages::Address < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "address"
- @header = "What is the property's address?"
+ @header = "Q12 - What is the property's address?"
end
def questions
diff --git a/app/models/form/lettings/questions/address_line1.rb b/app/models/form/lettings/questions/address_line1.rb
index 6f82edf45..b3288c82c 100644
--- a/app/models/form/lettings/questions/address_line1.rb
+++ b/app/models/form/lettings/questions/address_line1.rb
@@ -6,7 +6,7 @@ class Form::Lettings::Questions::AddressLine1 < ::Form::Question
@header = "Address line 1"
@type = "text"
@plain_label = true
- @question_number = 12
+ @check_answer_label = "Q12 - Address"
end
def hidden_in_check_answers?(log, _current_user = nil)
diff --git a/app/models/form/lettings/questions/uprn_known.rb b/app/models/form/lettings/questions/uprn_known.rb
index 6e3ce0302..d206885fb 100644
--- a/app/models/form/lettings/questions/uprn_known.rb
+++ b/app/models/form/lettings/questions/uprn_known.rb
@@ -3,7 +3,7 @@ class Form::Lettings::Questions::UprnKnown < ::Form::Question
super
@id = "uprn_known"
@check_answer_label = "UPRN known?"
- @header = "Do you know the property UPRN?"
+ @header = "Do you know the property's UPRN?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.
diff --git a/app/models/form/sales/pages/address.rb b/app/models/form/sales/pages/address.rb
index aa8ab7e0d..ca686d1b1 100644
--- a/app/models/form/sales/pages/address.rb
+++ b/app/models/form/sales/pages/address.rb
@@ -2,7 +2,7 @@ class Form::Sales::Pages::Address < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "address"
- @header = "What is the property's address?"
+ @header = "Q15 - What is the property's address?"
end
def questions
diff --git a/app/models/form/sales/questions/address_line1.rb b/app/models/form/sales/questions/address_line1.rb
index 2dd3a734e..a71229970 100644
--- a/app/models/form/sales/questions/address_line1.rb
+++ b/app/models/form/sales/questions/address_line1.rb
@@ -6,7 +6,7 @@ class Form::Sales::Questions::AddressLine1 < ::Form::Question
@header = "Address line 1"
@type = "text"
@plain_label = true
- @question_number = 15
+ @check_answer_label = "Q15 - Address"
end
def hidden_in_check_answers?(log, _current_user = nil)
diff --git a/app/models/form/sales/questions/uprn_known.rb b/app/models/form/sales/questions/uprn_known.rb
index 9f192f7de..b07b0b7d7 100644
--- a/app/models/form/sales/questions/uprn_known.rb
+++ b/app/models/form/sales/questions/uprn_known.rb
@@ -3,7 +3,7 @@ class Form::Sales::Questions::UprnKnown < ::Form::Question
super
@id = "uprn_known"
@check_answer_label = "UPRN known?"
- @header = "Do you know the property UPRN?"
+ @header = "Do you know the property's UPRN?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.
diff --git a/spec/models/form/lettings/pages/address_spec.rb b/spec/models/form/lettings/pages/address_spec.rb
index e4cf044b8..230d6964f 100644
--- a/spec/models/form/lettings/pages/address_spec.rb
+++ b/spec/models/form/lettings/pages/address_spec.rb
@@ -20,7 +20,7 @@ RSpec.describe Form::Lettings::Pages::Address, type: :model do
end
it "has the correct header" do
- expect(page.header).to eq("What is the property's address?")
+ expect(page.header).to eq("Q12 - What is the property's address?")
end
it "has the correct description" do
diff --git a/spec/models/form/lettings/questions/address_line1_spec.rb b/spec/models/form/lettings/questions/address_line1_spec.rb
index 781b0a748..e2600f0cc 100644
--- a/spec/models/form/lettings/questions/address_line1_spec.rb
+++ b/spec/models/form/lettings/questions/address_line1_spec.rb
@@ -20,11 +20,11 @@ RSpec.describe Form::Lettings::Questions::AddressLine1, type: :model do
end
it "has the correct question_number" do
- expect(question.question_number).to eq(12)
+ expect(question.question_number).to be_nil
end
it "has the correct check_answer_label" do
- expect(question.check_answer_label).to eq("Address")
+ expect(question.check_answer_label).to eq("Q12 - Address")
end
it "has the correct type" do
diff --git a/spec/models/form/lettings/questions/uprn_known_spec.rb b/spec/models/form/lettings/questions/uprn_known_spec.rb
index 1a0f810da..07eb72f8d 100644
--- a/spec/models/form/lettings/questions/uprn_known_spec.rb
+++ b/spec/models/form/lettings/questions/uprn_known_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe Form::Lettings::Questions::UprnKnown, type: :model do
end
it "has the correct header" do
- expect(question.header).to eq("Do you know the property UPRN?")
+ expect(question.header).to eq("Do you know the property's UPRN?")
end
it "has the correct check_answer_label" do
diff --git a/spec/models/form/sales/pages/address_spec.rb b/spec/models/form/sales/pages/address_spec.rb
index d6979b6b4..43a054a1e 100644
--- a/spec/models/form/sales/pages/address_spec.rb
+++ b/spec/models/form/sales/pages/address_spec.rb
@@ -20,7 +20,7 @@ RSpec.describe Form::Sales::Pages::Address, type: :model do
end
it "has the correct header" do
- expect(page.header).to eq("What is the property's address?")
+ expect(page.header).to eq("Q15 - What is the property's address?")
end
it "has the correct description" do
diff --git a/spec/models/form/sales/questions/address_line1_spec.rb b/spec/models/form/sales/questions/address_line1_spec.rb
index 27c0179e2..f037f41cd 100644
--- a/spec/models/form/sales/questions/address_line1_spec.rb
+++ b/spec/models/form/sales/questions/address_line1_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe Form::Sales::Questions::AddressLine1, type: :model do
end
it "has the correct question_number" do
- expect(question.question_number).to eq(15)
+ expect(question.question_number).to be_nil
end
it "has the correct id" do
@@ -24,7 +24,7 @@ RSpec.describe Form::Sales::Questions::AddressLine1, type: :model do
end
it "has the correct check_answer_label" do
- expect(question.check_answer_label).to eq("Address")
+ expect(question.check_answer_label).to eq("Q15 - Address")
end
it "has the correct type" do
diff --git a/spec/models/form/sales/questions/uprn_known_spec.rb b/spec/models/form/sales/questions/uprn_known_spec.rb
index 528e60a1f..457471568 100644
--- a/spec/models/form/sales/questions/uprn_known_spec.rb
+++ b/spec/models/form/sales/questions/uprn_known_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe Form::Sales::Questions::UprnKnown, type: :model do
end
it "has the correct header" do
- expect(question.header).to eq("Do you know the property UPRN?")
+ expect(question.header).to eq("Do you know the property's UPRN?")
end
it "has the correct check_answer_label" do
From 9f3b2bba28955e8f1bcd0f31f53ee17f3878f793 Mon Sep 17 00:00:00 2001
From: Arthur Campbell <51094020+arfacamble@users.noreply.github.com>
Date: Fri, 24 Mar 2023 15:44:09 +0000
Subject: [PATCH 4/4] CLDC-2032 test log creation in crossover period (#1420)
* ensure that no form is added to the forms hash under the key "nil"
* add a test to ensure that the form handler does not add outdated forms to the forms hash with key nil
* remove unnecessary singleton reinitialisation
* remove a duplicated Timecop around block
---
app/models/form_handler.rb | 2 +-
spec/models/form_handler_spec.rb | 11 +++++++++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb
index 12ae4473b..b2d9168b2 100644
--- a/app/models/form_handler.rb
+++ b/app/models/form_handler.rb
@@ -47,7 +47,7 @@ class FormHandler
form = Form.new(form_path)
form_to_set = form_name_from_start_year(form.start_date.year, "lettings")
- forms[form_to_set] = form if forms[form_to_set].blank?
+ forms[form_to_set] = form if form_to_set && forms[form_to_set].blank?
end
end
diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb
index 417da6639..ec2ddbecc 100644
--- a/spec/models/form_handler_spec.rb
+++ b/spec/models/form_handler_spec.rb
@@ -9,8 +9,6 @@ RSpec.describe FormHandler do
Singleton.__init__(described_class)
example.run
end
- Timecop.return
- Singleton.__init__(described_class)
end
context "when accessing a form in a different year" do
@@ -35,6 +33,15 @@ RSpec.describe FormHandler do
expect(all_forms.count).to be >= 1
expect(all_forms["current_sales"]).to be_a(Form)
end
+
+ context "when in 23/24 period or later" do
+ let(:now) { Time.utc(2023, 6, 7) }
+
+ it "does not load outdated forms" do
+ all_forms = form_handler.forms
+ expect(all_forms.keys).not_to include nil
+ end
+ end
end
describe "Get specific form" do