From 2f9e3d7d71e7386886f6c7fbbbab15d8b786fa2b Mon Sep 17 00:00:00 2001 From: Jack <113976590+bibblobcode@users.noreply.github.com> Date: Mon, 9 Jan 2023 16:02:03 +0000 Subject: [PATCH] [CLDC-1746] Add HandoverDate question (#1161) --- .../derived_variables/sales_log_variables.rb | 5 +++ app/models/form/sales/pages/handover_date.rb | 18 ++++++++++ .../form/sales/questions/handover_date.rb | 11 ++++++ .../subsections/shared_ownership_scheme.rb | 1 + ...06145107_add_handover_date_to_sales_log.rb | 8 +++++ db/schema.rb | 6 +++- .../form/sales/pages/handover_date_spec.rb | 35 +++++++++++++++++++ .../sales/questions/handover_date_spec.rb | 33 +++++++++++++++++ .../shared_ownership_scheme_spec.rb | 1 + spec/models/form_handler_spec.rb | 4 +-- 10 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 app/models/form/sales/pages/handover_date.rb create mode 100644 app/models/form/sales/questions/handover_date.rb create mode 100644 db/migrate/20230106145107_add_handover_date_to_sales_log.rb create mode 100644 spec/models/form/sales/pages/handover_date_spec.rb create mode 100644 spec/models/form/sales/questions/handover_date_spec.rb diff --git a/app/models/derived_variables/sales_log_variables.rb b/app/models/derived_variables/sales_log_variables.rb index c9675d84a..034816090 100644 --- a/app/models/derived_variables/sales_log_variables.rb +++ b/app/models/derived_variables/sales_log_variables.rb @@ -6,6 +6,11 @@ module DerivedVariables::SalesLogVariables self.exmonth = exdate.month self.exyear = exdate.year end + if hodate.present? + self.hoday = hodate.day + self.homonth = hodate.month + self.hoyear = hodate.year + end self.deposit = value if outright_sale? && mortgage_not_used? if mscharge_known.present? && mscharge_known.zero? self.mscharge = 0 diff --git a/app/models/form/sales/pages/handover_date.rb b/app/models/form/sales/pages/handover_date.rb new file mode 100644 index 000000000..a4216da40 --- /dev/null +++ b/app/models/form/sales/pages/handover_date.rb @@ -0,0 +1,18 @@ +class Form::Sales::Pages::HandoverDate < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "handover_date" + @header = "" + @description = "" + @subsection = subsection + @depends_on = [{ + "ownershipsch" => 1, + }] + end + + def questions + @questions ||= [ + Form::Sales::Questions::HandoverDate.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/handover_date.rb b/app/models/form/sales/questions/handover_date.rb new file mode 100644 index 000000000..b00f39601 --- /dev/null +++ b/app/models/form/sales/questions/handover_date.rb @@ -0,0 +1,11 @@ +class Form::Sales::Questions::HandoverDate < ::Form::Question + def initialize(id, hsh, page) + super + @id = "hodate" + @check_answer_label = "Practical completion or handover date" + @header = "What is the practical completion or handover date?" + @type = "date" + @page = page + @hint_text = "This is the date on which the building contractor hands over responsibility for the completed property to the private registered provider (PRP)" + end +end diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 043459adb..25b6c360b 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -14,6 +14,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::AboutStaircase.new(nil, nil, self), Form::Sales::Pages::Resale.new(nil, nil, self), Form::Sales::Pages::ExchangeDate.new(nil, nil, self), + Form::Sales::Pages::HandoverDate.new(nil, nil, self), Form::Sales::Pages::LaNominations.new(nil, nil, self), Form::Sales::Pages::BuyerPrevious.new(nil, nil, self), Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self), diff --git a/db/migrate/20230106145107_add_handover_date_to_sales_log.rb b/db/migrate/20230106145107_add_handover_date_to_sales_log.rb new file mode 100644 index 000000000..a724db43d --- /dev/null +++ b/db/migrate/20230106145107_add_handover_date_to_sales_log.rb @@ -0,0 +1,8 @@ +class AddHandoverDateToSalesLog < ActiveRecord::Migration[7.0] + change_table :sales_logs, bulk: true do |t| + t.column :hodate, :datetime + t.column :hoday, :integer + t.column :homonth, :integer + t.column :hoyear, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 9155a892f..a59ce5f0e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do +ActiveRecord::Schema[7.0].define(version: 2023_01_06_145107) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -466,6 +466,10 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do t.string "sex4" t.string "sex5" t.string "sex6" + t.datetime "hodate", precision: nil + t.integer "hoday" + t.integer "homonth" + t.integer "hoyear" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" diff --git a/spec/models/form/sales/pages/handover_date_spec.rb b/spec/models/form/sales/pages/handover_date_spec.rb new file mode 100644 index 000000000..fed507969 --- /dev/null +++ b/spec/models/form/sales/pages/handover_date_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::HandoverDate, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[hodate]) + end + + it "has the correct id" do + expect(page.id).to eq("handover_date") + end + + it "has the correct header" do + expect(page.header).to eq("") + end + + it "has the correct description" do + expect(page.description).to eq("") + end + + it "has the correct depends_on" do + expect(page.depends_on).to eq([{ + "ownershipsch" => 1, + }]) + end +end diff --git a/spec/models/form/sales/questions/handover_date_spec.rb b/spec/models/form/sales/questions/handover_date_spec.rb new file mode 100644 index 000000000..43fa7f665 --- /dev/null +++ b/spec/models/form/sales/questions/handover_date_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::HandoverDate, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("hodate") + end + + it "has the correct header" do + expect(question.header).to eq("What is the practical completion or handover date?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Practical completion or handover date") + end + + it "has the correct type" do + expect(question.type).to eq("date") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end +end diff --git a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb index 06f98ba09..fb326d359 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -19,6 +19,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do about_staircasing resale exchange_contracts + handover_date la_nominations buyer_previous previous_bedrooms diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 44ddbe3b8..3b2b70c33 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -52,14 +52,14 @@ RSpec.describe FormHandler do it "is able to load a current sales form" do form = form_handler.get_form("current_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(131) + expect(form.pages.count).to eq(132) expect(form.name).to eq("2022_2023_sales") end it "is able to load a previous sales form" do form = form_handler.get_form("previous_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(131) + expect(form.pages.count).to eq(132) expect(form.name).to eq("2021_2022_sales") end end