From 3c24d426ca2450d2d7c8d2c51cec3da8582e41f1 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 21 Sep 2022 17:23:10 +0100 Subject: [PATCH 01/17] feat: add boyer_company page and question (migration still to be committed) --- app/models/form/sales/pages/buyer_company.rb | 15 +++++++++++++++ .../form/sales/questions/buyer_company.rb | 17 +++++++++++++++++ app/models/form/sales/subsections/setup.rb | 1 + 3 files changed, 33 insertions(+) create mode 100644 app/models/form/sales/pages/buyer_company.rb create mode 100644 app/models/form/sales/questions/buyer_company.rb diff --git a/app/models/form/sales/pages/buyer_company.rb b/app/models/form/sales/pages/buyer_company.rb new file mode 100644 index 000000000..6985a3908 --- /dev/null +++ b/app/models/form/sales/pages/buyer_company.rb @@ -0,0 +1,15 @@ +class Form::Sales::Pages::BuyerCompany < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "buyer_company" + @header = "" + @description = "" + @subsection = subsection + end + + def questions + @questions ||= [ + Form::Sales::Questions::BuyerCompany.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/buyer_company.rb b/app/models/form/sales/questions/buyer_company.rb new file mode 100644 index 000000000..70c732866 --- /dev/null +++ b/app/models/form/sales/questions/buyer_company.rb @@ -0,0 +1,17 @@ +class Form::Sales::Questions::BuyerCompany < ::Form::Question + def initialize(id, hsh, page) + super + @id = "companybuy" + @check_answer_label = "Company buyer" + @header = "Is the buyer a company?" + @hint_text = "" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @page = page + end + + ANSWER_OPTIONS = { + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }.freeze +end diff --git a/app/models/form/sales/subsections/setup.rb b/app/models/form/sales/subsections/setup.rb index 5b966efe4..19fb854b5 100644 --- a/app/models/form/sales/subsections/setup.rb +++ b/app/models/form/sales/subsections/setup.rb @@ -16,6 +16,7 @@ class Form::Sales::Subsections::Setup < ::Form::Subsection Form::Sales::Pages::SharedOwnershipType.new(nil, nil, self), Form::Sales::Pages::DiscountedOwnershipType.new(nil, nil, self), Form::Sales::Pages::OutrightOwnershipType.new(nil, nil, self), + Form::Sales::Pages::BuyerCompany.new(nil, nil, self), Form::Sales::Pages::JointPurchase.new(nil, nil, self), ] end From 7cd54e7a5ecbe247aebd88868b07be3d5aa61aa0 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 22 Sep 2022 09:26:23 +0100 Subject: [PATCH 02/17] feat: add migration and updated schema --- db/migrate/20220921154025_add_company_buyer_to_sales_log.rb | 5 +++++ db/schema.rb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20220921154025_add_company_buyer_to_sales_log.rb diff --git a/db/migrate/20220921154025_add_company_buyer_to_sales_log.rb b/db/migrate/20220921154025_add_company_buyer_to_sales_log.rb new file mode 100644 index 000000000..89de76ca9 --- /dev/null +++ b/db/migrate/20220921154025_add_company_buyer_to_sales_log.rb @@ -0,0 +1,5 @@ +class AddCompanyBuyerToSalesLog < ActiveRecord::Migration[7.0] + def change + add_column :sales_logs, :companybuy, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 87714f00f..279cd7cd2 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: 2022_09_20_132907) do +ActiveRecord::Schema[7.0].define(version: 2022_09_21_154025) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -230,7 +230,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_20_132907) do t.bigint "location_id" t.integer "major_repairs_date_value_check" t.integer "void_date_value_check" - t.integer "housingneeds_type" t.integer "housingneeds_other" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id" t.index ["location_id"], name: "index_lettings_logs_on_location_id" @@ -326,6 +325,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_20_132907) do t.integer "ownershipsch" t.integer "jointpur" t.string "othtype" + t.integer "companybuy" 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" From 21201dc875b79eb1904d5d55b08c1356b22bf183 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 22 Sep 2022 16:27:31 +0100 Subject: [PATCH 03/17] feat: update tests (and add housingneeds_type to schema that was previously missing) --- db/schema.rb | 1 + spec/factories/sales_log.rb | 1 + spec/models/form/sales/subsections/setup_spec.rb | 2 +- spec/models/form_handler_spec.rb | 4 ++-- spec/models/form_spec.rb | 4 ++-- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 279cd7cd2..2d42a1d77 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -230,6 +230,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_21_154025) do t.bigint "location_id" t.integer "major_repairs_date_value_check" t.integer "void_date_value_check" + t.integer "housingneeds_type" t.integer "housingneeds_other" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id" t.index ["location_id"], name: "index_lettings_logs_on_location_id" diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index da656367f..b36c3dc8a 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -10,6 +10,7 @@ FactoryBot.define do ownershipsch { 2 } type { 8 } saledate { Time.utc(2022, 2, 2, 10, 36, 49) } + companybuy { 1 } jointpur { 1 } end end diff --git a/spec/models/form/sales/subsections/setup_spec.rb b/spec/models/form/sales/subsections/setup_spec.rb index 6b537ce04..4d06c5b6a 100644 --- a/spec/models/form/sales/subsections/setup_spec.rb +++ b/spec/models/form/sales/subsections/setup_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Form::Sales::Subsections::Setup, type: :model do it "has correct pages" do expect(setup.pages.map(&:id)).to eq( - %w[organisation created_by completion_date purchaser_code ownership_scheme shared_ownership_type discounted_ownership_type outright_ownership_type joint_purchase], + %w[organisation created_by completion_date purchaser_code ownership_scheme shared_ownership_type discounted_ownership_type outright_ownership_type buyer_company joint_purchase], ) end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 19bb10675..55d39e4e4 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -61,14 +61,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(9) + expect(form.pages.count).to eq(10) 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(9) + expect(form.pages.count).to eq(10) expect(form.name).to eq("2021_2022_sales") end end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index c9d2a3f36..c26667193 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -218,9 +218,9 @@ RSpec.describe Form, type: :model do expect(form.sections[0].class).to eq(Form::Sales::Sections::Setup) expect(form.subsections.count).to eq(1) expect(form.subsections.first.id).to eq("setup") - expect(form.pages.count).to eq(9) + expect(form.pages.count).to eq(10) expect(form.pages.first.id).to eq("organisation") - expect(form.questions.count).to eq(10) + expect(form.questions.count).to eq(11) expect(form.questions.first.id).to eq("owning_organisation_id") expect(form.start_date).to eq(Time.zone.parse("2022-04-01")) expect(form.end_date).to eq(Time.zone.parse("2023-07-01")) From ec6a1578fa6fcf6c3bca3ccc0a4040ccf5bc2c9d Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 23 Sep 2022 09:35:53 +0100 Subject: [PATCH 04/17] tests: add tests for question and page --- .../form/sales/pages/buyer_company_spec.rb | 29 ++++++++++++++ .../sales/questions/buyer_company_spec.rb | 40 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 spec/models/form/sales/pages/buyer_company_spec.rb create mode 100644 spec/models/form/sales/questions/buyer_company_spec.rb diff --git a/spec/models/form/sales/pages/buyer_company_spec.rb b/spec/models/form/sales/pages/buyer_company_spec.rb new file mode 100644 index 000000000..94b42c28b --- /dev/null +++ b/spec/models/form/sales/pages/buyer_company_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::BuyerCompany, 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[companybuy]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_company") + 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 +end diff --git a/spec/models/form/sales/questions/buyer_company_spec.rb b/spec/models/form/sales/questions/buyer_company_spec.rb new file mode 100644 index 000000000..88fe23acb --- /dev/null +++ b/spec/models/form/sales/questions/buyer_company_spec.rb @@ -0,0 +1,40 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::BuyerCompany, 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("companybuy") + end + + it "has the correct header" do + expect(question.header).to eq("Is the buyer a company?") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint_text" do + expect(question.hint_text).to eq("") + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }) + end +end From d597eb9d859e9a2aebca969b0b4207a9a70b19c1 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 23 Sep 2022 12:54:27 +0100 Subject: [PATCH 05/17] refactor: spacing --- spec/models/form/sales/questions/buyer_company_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/form/sales/questions/buyer_company_spec.rb b/spec/models/form/sales/questions/buyer_company_spec.rb index 88fe23acb..1d7d98940 100644 --- a/spec/models/form/sales/questions/buyer_company_spec.rb +++ b/spec/models/form/sales/questions/buyer_company_spec.rb @@ -33,8 +33,8 @@ RSpec.describe Form::Sales::Questions::BuyerCompany, type: :model do it "has the correct answer_options" do expect(question.answer_options).to eq({ - "1" => { "value" => "Yes" }, - "2" => { "value" => "No" }, - }) + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }) end end From 4696529c34289d630d6c861dee5319faf750d121 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 23 Sep 2022 13:40:13 +0100 Subject: [PATCH 06/17] feat: update schema --- db/schema.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index c2b54d354..db51c5a93 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -332,8 +332,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_23_093628) do t.string "purchid" t.integer "type" t.integer "ownershipsch" - t.string "othtype" t.integer "jointpur" + t.string "othtype" + t.integer "companybuy" 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" From 49ae302a94120560187992291f061da14d44e691 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 21 Sep 2022 17:23:10 +0100 Subject: [PATCH 07/17] feat: add boyer_company page and question (migration still to be committed) --- app/models/form/sales/pages/buyer_company.rb | 15 +++++++++++++++ .../form/sales/questions/buyer_company.rb | 17 +++++++++++++++++ app/models/form/sales/subsections/setup.rb | 1 + 3 files changed, 33 insertions(+) create mode 100644 app/models/form/sales/pages/buyer_company.rb create mode 100644 app/models/form/sales/questions/buyer_company.rb diff --git a/app/models/form/sales/pages/buyer_company.rb b/app/models/form/sales/pages/buyer_company.rb new file mode 100644 index 000000000..6985a3908 --- /dev/null +++ b/app/models/form/sales/pages/buyer_company.rb @@ -0,0 +1,15 @@ +class Form::Sales::Pages::BuyerCompany < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "buyer_company" + @header = "" + @description = "" + @subsection = subsection + end + + def questions + @questions ||= [ + Form::Sales::Questions::BuyerCompany.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/buyer_company.rb b/app/models/form/sales/questions/buyer_company.rb new file mode 100644 index 000000000..70c732866 --- /dev/null +++ b/app/models/form/sales/questions/buyer_company.rb @@ -0,0 +1,17 @@ +class Form::Sales::Questions::BuyerCompany < ::Form::Question + def initialize(id, hsh, page) + super + @id = "companybuy" + @check_answer_label = "Company buyer" + @header = "Is the buyer a company?" + @hint_text = "" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @page = page + end + + ANSWER_OPTIONS = { + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }.freeze +end diff --git a/app/models/form/sales/subsections/setup.rb b/app/models/form/sales/subsections/setup.rb index 2cc6f6886..f39926db3 100644 --- a/app/models/form/sales/subsections/setup.rb +++ b/app/models/form/sales/subsections/setup.rb @@ -16,6 +16,7 @@ class Form::Sales::Subsections::Setup < ::Form::Subsection Form::Sales::Pages::SharedOwnershipType.new(nil, nil, self), Form::Sales::Pages::DiscountedOwnershipType.new(nil, nil, self), Form::Sales::Pages::OutrightOwnershipType.new(nil, nil, self), + Form::Sales::Pages::BuyerCompany.new(nil, nil, self), Form::Sales::Pages::BuyerLive.new(nil, nil, self), Form::Sales::Pages::JointPurchase.new(nil, nil, self), Form::Sales::Pages::NumberJointBuyers.new(nil, nil, self), From b367c58971077df76fe45e8feb66a2af4a36fb6a Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 22 Sep 2022 09:26:23 +0100 Subject: [PATCH 08/17] feat: add migration and updated schema --- db/schema.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 5f86d013b..9b5b66837 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -235,7 +235,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_27_133123) do t.bigint "location_id" t.integer "major_repairs_date_value_check" t.integer "void_date_value_check" - t.integer "housingneeds_type" t.integer "housingneeds_other" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id" t.index ["location_id"], name: "index_lettings_logs_on_location_id" From 923d07f674d4f25f5f006258a6fe220d7cc14f66 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 22 Sep 2022 16:27:31 +0100 Subject: [PATCH 09/17] feat: update tests (and add housingneeds_type to schema that was previously missing) --- db/schema.rb | 1 + spec/factories/sales_log.rb | 1 + spec/models/form/sales/subsections/setup_spec.rb | 2 +- spec/models/form_spec.rb | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 9b5b66837..5f86d013b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -235,6 +235,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_27_133123) do t.bigint "location_id" t.integer "major_repairs_date_value_check" t.integer "void_date_value_check" + t.integer "housingneeds_type" t.integer "housingneeds_other" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id" t.index ["location_id"], name: "index_lettings_logs_on_location_id" diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index 035c981b1..7458ecb74 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -16,6 +16,7 @@ FactoryBot.define do ownershipsch { 2 } type { 8 } saledate { Time.utc(2022, 2, 2, 10, 36, 49) } + companybuy { 1 } jointpur { 1 } beds { 2 } jointmore { 1 } diff --git a/spec/models/form/sales/subsections/setup_spec.rb b/spec/models/form/sales/subsections/setup_spec.rb index 054b45249..e2285afca 100644 --- a/spec/models/form/sales/subsections/setup_spec.rb +++ b/spec/models/form/sales/subsections/setup_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Form::Sales::Subsections::Setup, type: :model do it "has correct pages" do expect(setup.pages.map(&:id)).to eq( - %w[organisation created_by completion_date purchaser_code ownership_scheme shared_ownership_type discounted_ownership_type outright_ownership_type buyer_live joint_purchase number_joint_buyers], + %w[organisation created_by completion_date purchaser_code ownership_scheme shared_ownership_type discounted_ownership_type outright_ownership_type buyer_live joint_purchase buyer_company number_joint_buyers], ) end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index a55c404d7..c4da6ecf4 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -218,9 +218,9 @@ RSpec.describe Form, type: :model do expect(form.sections[0].class).to eq(Form::Sales::Sections::Setup) expect(form.subsections.count).to eq(1) expect(form.subsections.first.id).to eq("setup") - expect(form.pages.count).to eq(11) + expect(form.pages.count).to eq(12) expect(form.pages.first.id).to eq("organisation") - expect(form.questions.count).to eq(12) + expect(form.questions.count).to eq(13) expect(form.questions.first.id).to eq("owning_organisation_id") expect(form.start_date).to eq(Time.zone.parse("2022-04-01")) expect(form.end_date).to eq(Time.zone.parse("2023-07-01")) From 223f4e072b79136cc2547ec6d6d7391d5acec7ed Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 23 Sep 2022 09:35:53 +0100 Subject: [PATCH 10/17] tests: add tests for question and page --- .../form/sales/pages/buyer_company_spec.rb | 29 ++++++++++++++ .../sales/questions/buyer_company_spec.rb | 40 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 spec/models/form/sales/pages/buyer_company_spec.rb create mode 100644 spec/models/form/sales/questions/buyer_company_spec.rb diff --git a/spec/models/form/sales/pages/buyer_company_spec.rb b/spec/models/form/sales/pages/buyer_company_spec.rb new file mode 100644 index 000000000..94b42c28b --- /dev/null +++ b/spec/models/form/sales/pages/buyer_company_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::BuyerCompany, 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[companybuy]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_company") + 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 +end diff --git a/spec/models/form/sales/questions/buyer_company_spec.rb b/spec/models/form/sales/questions/buyer_company_spec.rb new file mode 100644 index 000000000..88fe23acb --- /dev/null +++ b/spec/models/form/sales/questions/buyer_company_spec.rb @@ -0,0 +1,40 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::BuyerCompany, 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("companybuy") + end + + it "has the correct header" do + expect(question.header).to eq("Is the buyer a company?") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint_text" do + expect(question.hint_text).to eq("") + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }) + end +end From 6ddf59f8e33d9d7f1d90253dc2c25ab7ebaeae1b Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 23 Sep 2022 12:54:27 +0100 Subject: [PATCH 11/17] refactor: spacing --- spec/models/form/sales/questions/buyer_company_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/form/sales/questions/buyer_company_spec.rb b/spec/models/form/sales/questions/buyer_company_spec.rb index 88fe23acb..1d7d98940 100644 --- a/spec/models/form/sales/questions/buyer_company_spec.rb +++ b/spec/models/form/sales/questions/buyer_company_spec.rb @@ -33,8 +33,8 @@ RSpec.describe Form::Sales::Questions::BuyerCompany, type: :model do it "has the correct answer_options" do expect(question.answer_options).to eq({ - "1" => { "value" => "Yes" }, - "2" => { "value" => "No" }, - }) + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }) end end From 0acf0dbda8805ad80b05b2e53204bf105a80cec4 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 28 Sep 2022 11:28:37 +0100 Subject: [PATCH 12/17] feat: update test --- spec/models/form/sales/subsections/setup_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/form/sales/subsections/setup_spec.rb b/spec/models/form/sales/subsections/setup_spec.rb index e2285afca..e5d94d6d4 100644 --- a/spec/models/form/sales/subsections/setup_spec.rb +++ b/spec/models/form/sales/subsections/setup_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Form::Sales::Subsections::Setup, type: :model do it "has correct pages" do expect(setup.pages.map(&:id)).to eq( - %w[organisation created_by completion_date purchaser_code ownership_scheme shared_ownership_type discounted_ownership_type outright_ownership_type buyer_live joint_purchase buyer_company number_joint_buyers], + %w[organisation created_by completion_date purchaser_code ownership_scheme shared_ownership_type discounted_ownership_type outright_ownership_type buyer_company buyer_live joint_purchase number_joint_buyers], ) end From 6e6d13f7186df6798b0ed051902cb90c8488d176 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 21 Sep 2022 17:23:10 +0100 Subject: [PATCH 13/17] feat: add boyer_company page and question (migration still to be committed) --- app/models/form/sales/pages/buyer_company.rb | 15 +++++++++++++++ .../form/sales/questions/buyer_company.rb | 17 +++++++++++++++++ app/models/form/sales/subsections/setup.rb | 1 + 3 files changed, 33 insertions(+) create mode 100644 app/models/form/sales/pages/buyer_company.rb create mode 100644 app/models/form/sales/questions/buyer_company.rb diff --git a/app/models/form/sales/pages/buyer_company.rb b/app/models/form/sales/pages/buyer_company.rb new file mode 100644 index 000000000..6985a3908 --- /dev/null +++ b/app/models/form/sales/pages/buyer_company.rb @@ -0,0 +1,15 @@ +class Form::Sales::Pages::BuyerCompany < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "buyer_company" + @header = "" + @description = "" + @subsection = subsection + end + + def questions + @questions ||= [ + Form::Sales::Questions::BuyerCompany.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/buyer_company.rb b/app/models/form/sales/questions/buyer_company.rb new file mode 100644 index 000000000..70c732866 --- /dev/null +++ b/app/models/form/sales/questions/buyer_company.rb @@ -0,0 +1,17 @@ +class Form::Sales::Questions::BuyerCompany < ::Form::Question + def initialize(id, hsh, page) + super + @id = "companybuy" + @check_answer_label = "Company buyer" + @header = "Is the buyer a company?" + @hint_text = "" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @page = page + end + + ANSWER_OPTIONS = { + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }.freeze +end diff --git a/app/models/form/sales/subsections/setup.rb b/app/models/form/sales/subsections/setup.rb index 7601bbb51..b9ba89dcf 100644 --- a/app/models/form/sales/subsections/setup.rb +++ b/app/models/form/sales/subsections/setup.rb @@ -16,6 +16,7 @@ class Form::Sales::Subsections::Setup < ::Form::Subsection Form::Sales::Pages::SharedOwnershipType.new(nil, nil, self), Form::Sales::Pages::DiscountedOwnershipType.new(nil, nil, self), Form::Sales::Pages::OutrightOwnershipType.new(nil, nil, self), + Form::Sales::Pages::BuyerCompany.new(nil, nil, self), Form::Sales::Pages::BuyerLive.new(nil, nil, self), Form::Sales::Pages::JointPurchase.new(nil, nil, self), Form::Sales::Pages::NumberJointBuyers.new(nil, nil, self), From 0c4d064fe40445161208a5691eae04fd6ec0b044 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 22 Sep 2022 09:26:23 +0100 Subject: [PATCH 14/17] feat: add migration and updated schema --- db/schema.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index fa885644b..d6e5673a8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -235,7 +235,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_29_125204) do t.bigint "location_id" t.integer "major_repairs_date_value_check" t.integer "void_date_value_check" - t.integer "housingneeds_type" t.integer "housingneeds_other" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id" t.index ["location_id"], name: "index_lettings_logs_on_location_id" From 1ddcbd4897901824a2fac8e0e880497e3b6d0435 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 22 Sep 2022 16:27:31 +0100 Subject: [PATCH 15/17] feat: update tests (and add housingneeds_type to schema that was previously missing) --- db/schema.rb | 1 + spec/factories/sales_log.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/db/schema.rb b/db/schema.rb index d6e5673a8..fa885644b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -235,6 +235,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_29_125204) do t.bigint "location_id" t.integer "major_repairs_date_value_check" t.integer "void_date_value_check" + t.integer "housingneeds_type" t.integer "housingneeds_other" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id" t.index ["location_id"], name: "index_lettings_logs_on_location_id" diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index 670131681..0a8a56ee0 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -16,6 +16,7 @@ FactoryBot.define do ownershipsch { 2 } type { 8 } saledate { Time.utc(2022, 2, 2, 10, 36, 49) } + companybuy { 1 } jointpur { 1 } beds { 2 } jointmore { 1 } From f9d759a754e0b3be801f313a6e31ee65767d1356 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 23 Sep 2022 09:35:53 +0100 Subject: [PATCH 16/17] tests: add tests for question and page --- .../form/sales/pages/buyer_company_spec.rb | 29 ++++++++++++++ .../sales/questions/buyer_company_spec.rb | 40 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 spec/models/form/sales/pages/buyer_company_spec.rb create mode 100644 spec/models/form/sales/questions/buyer_company_spec.rb diff --git a/spec/models/form/sales/pages/buyer_company_spec.rb b/spec/models/form/sales/pages/buyer_company_spec.rb new file mode 100644 index 000000000..94b42c28b --- /dev/null +++ b/spec/models/form/sales/pages/buyer_company_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::BuyerCompany, 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[companybuy]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_company") + 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 +end diff --git a/spec/models/form/sales/questions/buyer_company_spec.rb b/spec/models/form/sales/questions/buyer_company_spec.rb new file mode 100644 index 000000000..88fe23acb --- /dev/null +++ b/spec/models/form/sales/questions/buyer_company_spec.rb @@ -0,0 +1,40 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::BuyerCompany, 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("companybuy") + end + + it "has the correct header" do + expect(question.header).to eq("Is the buyer a company?") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint_text" do + expect(question.hint_text).to eq("") + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }) + end +end From b4848c3cd8224357c6d8666ed8bcbc62503d8e36 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 23 Sep 2022 12:54:27 +0100 Subject: [PATCH 17/17] refactor: spacing --- spec/models/form/sales/questions/buyer_company_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/form/sales/questions/buyer_company_spec.rb b/spec/models/form/sales/questions/buyer_company_spec.rb index 88fe23acb..1d7d98940 100644 --- a/spec/models/form/sales/questions/buyer_company_spec.rb +++ b/spec/models/form/sales/questions/buyer_company_spec.rb @@ -33,8 +33,8 @@ RSpec.describe Form::Sales::Questions::BuyerCompany, type: :model do it "has the correct answer_options" do expect(question.answer_options).to eq({ - "1" => { "value" => "Yes" }, - "2" => { "value" => "No" }, - }) + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }) end end