Browse Source

CLDC-1808 add previous tenure question for buyer two (#1354)

* create and run migration for new columns related to buyer two previous tenure

* a little refactoring for readability

* create new pages, questions, associated tests and a couple of boolean methods on sales log for depends_on readability

* add new pages to subsection and amend tests to reflect this change

* make new pages only visible for new collection year, rename filesamend tests

* some copy changes and alterations of readability after code review
pull/1409/head
Arthur Campbell 2 years ago committed by GitHub
parent
commit
285b8ec61f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/models/form/sales/pages/buyer2_live_in_property.rb
  2. 11
      app/models/form/sales/pages/buyer2_living_in.rb
  3. 11
      app/models/form/sales/pages/buyer2_previous_housing_situation.rb
  4. 17
      app/models/form/sales/questions/buyer2_living_in.rb
  5. 23
      app/models/form/sales/questions/previous_tenure_buyer2.rb
  6. 12
      app/models/form/sales/subsections/household_situation.rb
  7. 12
      app/models/sales_log.rb
  8. 8
      db/migrate/20230224083552_add_columns_to_sales_log.rb
  9. 2
      db/schema.rb
  10. 6
      spec/models/form/sales/pages/buyer2_live_in_property_spec.rb
  11. 31
      spec/models/form/sales/pages/buyer2_living_in_spec.rb
  12. 31
      spec/models/form/sales/pages/buyer2_previous_housing_situation_spec.rb
  13. 43
      spec/models/form/sales/questions/buyer2_living_in_spec.rb
  14. 49
      spec/models/form/sales/questions/previous_tenure_buyer2_spec.rb
  15. 45
      spec/models/form/sales/subsections/household_situation_spec.rb

6
app/models/form/sales/pages/buyer2_live_in_property.rb

@ -4,12 +4,12 @@ class Form::Sales::Pages::Buyer2LiveInProperty < ::Form::Page
@id = "buyer_2_live_in_property"
@depends_on = [
{
"jointpur" => 1,
"joint_purchase?" => true,
"privacynotice" => 1,
},
{
"jointpur" => 1,
"noint" => 1,
"joint_purchase?" => true,
"buyer_not_interviewed?" => true,
},
]
end

11
app/models/form/sales/pages/buyer2_living_in.rb

@ -0,0 +1,11 @@
class Form::Sales::Pages::Buyer2LivingIn < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_2_living_in"
@depends_on = [{ "buyer_two_will_live_in_property?" => true }]
end
def questions
@questions = [Form::Sales::Questions::Buyer2LivingIn.new(nil, nil, self)]
end
end

11
app/models/form/sales/pages/buyer2_previous_housing_situation.rb

@ -0,0 +1,11 @@
class Form::Sales::Pages::Buyer2PreviousHousingSituation < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_2_previous_housing_situation"
@depends_on = [{ "buyer_two_not_already_living_in_property?" => true }]
end
def questions
@questions = [Form::Sales::Questions::PreviousTenureBuyer2.new(nil, nil, self)]
end
end

17
app/models/form/sales/questions/buyer2_living_in.rb

@ -0,0 +1,17 @@
class Form::Sales::Questions::Buyer2LivingIn < ::Form::Question
def initialize(id, hsh, page)
super
@id = "buy2living"
@check_answer_label = "Buyer 2 living at the same address"
@header = "At the time of purchase, was buyer 2 living at the same address as buyer 1?"
@type = "radio"
@hint_text = ""
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don't know" },
}.freeze
end

23
app/models/form/sales/questions/previous_tenure_buyer2.rb

@ -0,0 +1,23 @@
class Form::Sales::Questions::PreviousTenureBuyer2 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "prevtenbuy2"
@check_answer_label = "Buyer 2’s previous tenure"
@header = "What was buyer 2’s previous tenure?"
@type = "radio"
@hint_text = ""
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = {
"1" => { "value" => "Local Authority" },
"2" => { "value" => "Private registered provider or housing association tenant" },
"3" => { "value" => "Private tenant" },
"5" => { "value" => "Owner occupier" },
"4" => { "value" => "Tied home or renting with job" },
"6" => { "value" => "Living with family or friends" },
"7" => { "value" => "Temporary accomodation" },
"9" => { "value" => "Other" },
"0" => { "value" => "Don't know" },
}.freeze
end

12
app/models/form/sales/subsections/household_situation.rb

@ -12,6 +12,16 @@ class Form::Sales::Subsections::HouseholdSituation < ::Form::Subsection
Form::Sales::Pages::LastAccommodation.new(nil, nil, self),
Form::Sales::Pages::LastAccommodationLa.new(nil, nil, self),
Form::Sales::Pages::BuyersOrganisations.new(nil, nil, self),
]
buyer_2_situation_pages,
].flatten.compact
end
def buyer_2_situation_pages
if form.start_date.year >= 2023
[
Form::Sales::Pages::Buyer2LivingIn.new(nil, nil, self),
Form::Sales::Pages::Buyer2PreviousHousingSituation.new(nil, nil, self),
]
end
end
end

12
app/models/sales_log.rb

@ -151,6 +151,14 @@ class SalesLog < Log
inc1mort == 1
end
def buyer_two_will_live_in_property?
buy2livein == 1
end
def buyer_two_not_already_living_in_property?
buy2living == 2
end
def income2_used_for_mortgage?
inc2mort == 1
end
@ -250,6 +258,10 @@ class SalesLog < Log
jointpur == 2
end
def buyer_not_interviewed?
noint == 1
end
def old_persons_shared_ownership?
type == 24
end

8
db/migrate/20230224083552_add_columns_to_sales_log.rb

@ -0,0 +1,8 @@
class AddColumnsToSalesLog < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :buy2living, :integer
t.column :prevtenbuy2, :integer
end
end
end

2
db/schema.rb

@ -543,6 +543,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do
t.integer "proplen_asked"
t.string "old_id"
t.integer "pregblank"
t.integer "buy2living"
t.integer "prevtenbuy2"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["old_id"], name: "index_sales_logs_on_old_id", unique: true

6
spec/models/form/sales/pages/buyer2_live_in_property_spec.rb

@ -30,12 +30,12 @@ RSpec.describe Form::Sales::Pages::Buyer2LiveInProperty, type: :model do
it "has correct depends_on" do
expect(page.depends_on).to eq([
{
"jointpur" => 1,
"joint_purchase?" => true,
"privacynotice" => 1,
},
{
"jointpur" => 1,
"noint" => 1,
"joint_purchase?" => true,
"buyer_not_interviewed?" => true,
},
])
end

31
spec/models/form/sales/pages/buyer2_living_in_spec.rb

@ -0,0 +1,31 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer2LivingIn, type: :model do
subject(:page) { described_class.new(nil, nil, subsection) }
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[buy2living])
end
it "has the correct id" do
expect(page.id).to eq("buyer_2_living_in")
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "buyer_two_will_live_in_property?" => true }])
end
end

31
spec/models/form/sales/pages/buyer2_previous_housing_situation_spec.rb

@ -0,0 +1,31 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer2PreviousHousingSituation, type: :model do
subject(:page) { described_class.new(nil, nil, subsection) }
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[prevtenbuy2])
end
it "has the correct id" do
expect(page.id).to eq("buyer_2_previous_housing_situation")
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "buyer_two_not_already_living_in_property?" => true }])
end
end

43
spec/models/form/sales/questions/buyer2_living_in_spec.rb

@ -0,0 +1,43 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer2LivingIn, type: :model do
subject(:question) { described_class.new(nil, nil, page) }
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 "buy2living"
end
it "has the correct header" do
expect(question.header).to eq "At the time of purchase, was buyer 2 living at the same address as buyer 1?"
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq "Buyer 2 living at the same address"
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" },
"3" => { "value" => "Don't know" },
})
end
end

49
spec/models/form/sales/questions/previous_tenure_buyer2_spec.rb

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::PreviousTenureBuyer2, type: :model do
subject(:question) { described_class.new(nil, nil, page) }
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("prevtenbuy2")
end
it "has the correct header" do
expect(question.header).to eq("What was buyer 2’s previous tenure?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 2’s previous tenure")
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" => "Local Authority" },
"2" => { "value" => "Private registered provider or housing association tenant" },
"3" => { "value" => "Private tenant" },
"5" => { "value" => "Owner occupier" },
"4" => { "value" => "Tied home or renting with job" },
"6" => { "value" => "Living with family or friends" },
"7" => { "value" => "Temporary accomodation" },
"9" => { "value" => "Other" },
"0" => { "value" => "Don't know" },
})
end
end

45
spec/models/form/sales/subsections/household_situation_spec.rb

@ -1,25 +1,44 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::HouseholdSituation, type: :model do
subject(:household_characteristics) { described_class.new(subsection_id, subsection_definition, section) }
subject(:household_characteristics) { described_class.new(nil, nil, section) }
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Sales::Sections::Household) }
let(:start_date) { Time.utc(2023, 4, 1) }
let(:form) { instance_double(Form, start_date:) }
let(:section) { instance_double(Form::Sales::Sections::Household, form:) }
it "has correct section" do
expect(household_characteristics.section).to eq(section)
end
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
buyer1_previous_tenure
last_accommodation
last_accommodation_la
buyers_organisations
],
)
context "when the log belongs to the 22/23 collection" do
let(:start_date) { Time.utc(2022, 4, 1) }
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
buyer1_previous_tenure
last_accommodation
last_accommodation_la
buyers_organisations
],
)
end
end
context "when the log belongs to the 23/24 collection" do
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
buyer1_previous_tenure
last_accommodation
last_accommodation_la
buyers_organisations
buyer_2_living_in
buyer_2_previous_housing_situation
],
)
end
end
it "has the correct id" do

Loading…
Cancel
Save