Browse Source

Merge 5da8e34fc0 into af3330df00

pull/3174/merge
Oscar Richardson 5 days ago committed by GitHub
parent
commit
daf8be70f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      app/models/form/lettings/pages/tenancyother_value_check.rb
  2. 13
      app/models/form/lettings/questions/tenancyother_value_check.rb
  3. 1
      app/models/form/lettings/subsections/tenancy_information.rb
  4. 10
      app/models/validations/soft_validations.rb
  5. 10
      config/locales/forms/2026/lettings/soft_validations.en.yml
  6. 5
      db/migrate/20260212091506_add_tenancyother_value_check_to_lettings_logs.rb
  7. 3
      db/schema.rb
  8. 6
      spec/fixtures/files/lettings_log_csv_export_codes_26.csv
  9. 6
      spec/fixtures/files/lettings_log_csv_export_labels_26.csv
  10. 20
      spec/models/form/lettings/subsections/tenancy_information_spec.rb
  11. 38
      spec/models/validations/soft_validations_spec.rb

24
app/models/form/lettings/pages/tenancyother_value_check.rb

@ -0,0 +1,24 @@
class Form::Lettings::Pages::TenancyotherValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "tenancyother_value_check"
@copy_key = "lettings.soft_validations.tenancyother_value_check"
@depends_on = [{ "tenancyother_might_be_introductory_or_starter_period?" => true }]
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [{ "key" => "tenancyother", "i18n_template" => "tenancyother" }],
}
@informative_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text",
"arguments" => [],
}
end
def questions
@questions ||= [Form::Lettings::Questions::TenancyotherValueCheck.new(nil, nil, self)]
end
def interruption_screen_question_ids
%w[tenancy tenancyother]
end
end

13
app/models/form/lettings/questions/tenancyother_value_check.rb

@ -0,0 +1,13 @@
class Form::Lettings::Questions::TenancyotherValueCheck < ::Form::Question
def initialize(id, hsh, page)
super
@id = "tenancyother_value_check"
@copy_key = "lettings.soft_validations.tenancyother_value_check"
@type = "interruption_screen"
@check_answers_card_number = 0
@answer_options = ANSWER_OPTIONS
@hidden_in_check_answers = { "depends_on" => [{ "tenancyother_value_check" => 0 }, { "tenancyother_value_check" => 1 }] }
end
ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze
end

1
app/models/form/lettings/subsections/tenancy_information.rb

@ -12,6 +12,7 @@ class Form::Lettings::Subsections::TenancyInformation < ::Form::Subsection
Form::Lettings::Pages::StarterTenancy.new("starter_tenancy", nil, self), Form::Lettings::Pages::StarterTenancy.new("starter_tenancy", nil, self),
Form::Lettings::Pages::TenancyType.new(nil, nil, self), Form::Lettings::Pages::TenancyType.new(nil, nil, self),
Form::Lettings::Pages::StarterTenancyType.new(nil, nil, self), Form::Lettings::Pages::StarterTenancyType.new(nil, nil, self),
(Form::Lettings::Pages::TenancyotherValueCheck.new(nil, nil, self) if form.start_year_2026_or_later?),
Form::Lettings::Pages::TenancyLength.new(nil, nil, self), Form::Lettings::Pages::TenancyLength.new(nil, nil, self),
Form::Lettings::Pages::TenancyLengthAffordableRent.new(nil, nil, self), Form::Lettings::Pages::TenancyLengthAffordableRent.new(nil, nil, self),
Form::Lettings::Pages::TenancyLengthIntermediateRent.new(nil, nil, self), Form::Lettings::Pages::TenancyLengthIntermediateRent.new(nil, nil, self),

10
app/models/validations/soft_validations.rb

@ -208,6 +208,16 @@ module Validations::SoftValidations
PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY_REGEX.match?(reasonother) PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY_REGEX.match?(reasonother)
end end
PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD = %w[introductory intro starter].freeze
PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD_REGEX = Regexp.union(
PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD.map { |phrase| Regexp.new("\\b[^[:alpha]]*#{phrase}[^[:alpha:]]*\\b", Regexp::IGNORECASE) },
)
def tenancyother_might_be_introductory_or_starter_period?
PHRASES_LIKELY_TO_INDICATE_INTRODUCTORY_OR_STARTER_PERIOD_REGEX.match?(tenancyother)
end
def multiple_partners? def multiple_partners?
return unless hhmemb return unless hhmemb

10
config/locales/forms/2026/lettings/soft_validations.en.yml

@ -57,6 +57,16 @@ en:
title_text: "You told us that the tenant’s main reason for leaving their last settled home was %{reasonother}." title_text: "You told us that the tenant’s main reason for leaving their last settled home was %{reasonother}."
informative_text: "The reason you have entered looks very similar to one of the existing response categories. Please check the categories and select the appropriate one. If the existing categories are not suitable, please confirm here to move onto the next question." informative_text: "The reason you have entered looks very similar to one of the existing response categories. Please check the categories and select the appropriate one. If the existing categories are not suitable, please confirm here to move onto the next question."
tenancyother_value_check:
page_header: ""
check_answer_label: "Tenancy other confirmation"
check_answer_prompt: "Confirm tenancy type"
hint_text: ""
question_text: ""
title_text: "You told us that the type of tenancy was %{tenancyother}."
informative_text: "Give the type of tenancy that the tenants rolls onto after any introductory or starter period."
referral_value_check: referral_value_check:
page_header: "" page_header: ""
check_answer_label: "Referral confirmation" check_answer_label: "Referral confirmation"

5
db/migrate/20260212091506_add_tenancyother_value_check_to_lettings_logs.rb

@ -0,0 +1,5 @@
class AddTenancyotherValueCheckToLettingsLogs < ActiveRecord::Migration[7.0]
def change
add_column :lettings_logs, :tenancyother_value_check, :integer
end
end

3
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[7.2].define(version: 2026_01_28_121417) do ActiveRecord::Schema[7.2].define(version: 2026_02_12_091506) 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"
@ -384,6 +384,7 @@ ActiveRecord::Schema[7.2].define(version: 2026_01_28_121417) do
t.string "sexrab6" t.string "sexrab6"
t.string "sexrab7" t.string "sexrab7"
t.string "sexrab8" t.string "sexrab8"
t.integer "tenancyother_value_check"
t.index ["assigned_to_id"], name: "index_lettings_logs_on_assigned_to_id" t.index ["assigned_to_id"], name: "index_lettings_logs_on_assigned_to_id"
t.index ["bulk_upload_id"], name: "index_lettings_logs_on_bulk_upload_id" t.index ["bulk_upload_id"], name: "index_lettings_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id"

6
spec/fixtures/files/lettings_log_csv_export_codes_26.csv vendored

File diff suppressed because one or more lines are too long

6
spec/fixtures/files/lettings_log_csv_export_labels_26.csv vendored

File diff suppressed because one or more lines are too long

20
spec/models/form/lettings/subsections/tenancy_information_spec.rb

@ -18,6 +18,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true) allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(false) allow(form).to receive(:start_year_2025_or_later?).and_return(false)
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end end
context "when 2023" do context "when 2023" do
@ -26,6 +27,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(false) allow(form).to receive(:start_year_2024_or_later?).and_return(false)
allow(form).to receive(:start_year_2025_or_later?).and_return(false) allow(form).to receive(:start_year_2025_or_later?).and_return(false)
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end end
it "has correct pages" do it "has correct pages" do
@ -41,6 +43,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true) allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(false) allow(form).to receive(:start_year_2025_or_later?).and_return(false)
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end end
it "has correct pages" do it "has correct pages" do
@ -56,6 +59,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
before do before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true) allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(true) allow(form).to receive(:start_year_2025_or_later?).and_return(true)
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end end
it "has correct pages" do it "has correct pages" do
@ -64,6 +68,22 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
) )
end end
end end
context "when 2026" do
let(:start_date) { Time.utc(2026, 2, 8) }
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(true)
allow(form).to receive(:start_year_2026_or_later?).and_return(true)
end
it "has correct pages" do
expect(tenancy_information.pages.map(&:id)).to eq(
%w[joint starter_tenancy tenancy_type starter_tenancy_type tenancyother_value_check tenancy_length tenancy_length_affordable_rent tenancy_length_intermediate_rent tenancy_length_periodic],
)
end
end
end end
it "has the correct id" do it "has the correct id" do

38
spec/models/validations/soft_validations_spec.rb

@ -1355,6 +1355,44 @@ RSpec.describe Validations::SoftValidations do
end end
end end
describe "tenancyother_might_be_introductory_or_starter_period?" do
it "returns true if tenancyother is exactly in the 'likely introductory/starter period' list" do
record.tenancyother = "introductory"
expect(record).to be_tenancyother_might_be_introductory_or_starter_period
end
it "returns true if any word of tenancyother is exactly in the 'likely introductory/starter period' list" do
record.tenancyother = "a starter tenancy"
expect(record).to be_tenancyother_might_be_introductory_or_starter_period
end
it "is not case sensitive when matching" do
record.tenancyother = "Intro"
expect(record).to be_tenancyother_might_be_introductory_or_starter_period
end
it "returns false if no part of tenancyother is in the 'likely introductory/starter period' list" do
record.tenancyother = "other"
expect(record).not_to be_tenancyother_might_be_introductory_or_starter_period
end
it "returns false if match to the 'likely introductory/starter period' list is only part of a word" do
record.tenancyother = "wasintroductory"
expect(record).not_to be_tenancyother_might_be_introductory_or_starter_period
end
it "ignores neighbouring non-alphabet for matching" do
record.tenancyother = "1starter."
expect(record).to be_tenancyother_might_be_introductory_or_starter_period
end
end
describe "at_least_one_working_situation_is_sickness_and_household_sickness_is_no" do describe "at_least_one_working_situation_is_sickness_and_household_sickness_is_no" do
it "returns true if one person has working situation as illness and household sickness is no" do it "returns true if one person has working situation as illness and household sickness is no" do
record.illness = 2 record.illness = 2

Loading…
Cancel
Save