diff --git a/app/models/form/sales/pages/about_staircase.rb b/app/models/form/sales/pages/about_staircase.rb index fd740c10e..2d1a17db4 100644 --- a/app/models/form/sales/pages/about_staircase.rb +++ b/app/models/form/sales/pages/about_staircase.rb @@ -12,6 +12,13 @@ class Form::Sales::Pages::AboutStaircase < ::Form::Page @questions ||= [ Form::Sales::Questions::StaircaseBought.new(nil, nil, self), Form::Sales::Questions::StaircaseOwned.new(nil, nil, self), - ] + staircase_sale_question, + ].compact + end + + def staircase_sale_question + if form.start_date.year >= 2023 + Form::Sales::Questions::StaircaseSale.new(nil, nil, self) + end end end diff --git a/app/models/form/sales/questions/staircase_sale.rb b/app/models/form/sales/questions/staircase_sale.rb new file mode 100644 index 000000000..fb56572cf --- /dev/null +++ b/app/models/form/sales/questions/staircase_sale.rb @@ -0,0 +1,16 @@ +class Form::Sales::Questions::StaircaseSale < ::Form::Question + def initialize(id, hsh, page) + super + @id = "staircasesale" + @check_answer_label = "Part of a back-to-back staircasing transaction" + @header = "Is this transaction part of a back-to-back staircasing transaction to facilitate sale of the home on the open market?" + @type = "radio" + @answer_options = ANSWER_OPTIONS + end + + ANSWER_OPTIONS = { + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + "3" => { "value" => "Don't know" }, + }.freeze +end diff --git a/db/migrate/20230210122037_add_staircasesale_to_sales_logs.rb b/db/migrate/20230210122037_add_staircasesale_to_sales_logs.rb new file mode 100644 index 000000000..824549cff --- /dev/null +++ b/db/migrate/20230210122037_add_staircasesale_to_sales_logs.rb @@ -0,0 +1,5 @@ +class AddStaircasesaleToSalesLogs < ActiveRecord::Migration[7.0] + def change + add_column :sales_logs, :staircasesale, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 195315675..679b582c1 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_02_03_174815) do +ActiveRecord::Schema[7.0].define(version: 2023_02_10_122037) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -524,6 +524,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_03_174815) do t.integer "details_known_5" t.integer "details_known_6" t.integer "saledate_check" + t.integer "staircasesale" t.integer "prevshared" 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" diff --git a/spec/models/form/sales/pages/about_staircase_spec.rb b/spec/models/form/sales/pages/about_staircase_spec.rb index a2fba103e..3828f52e4 100644 --- a/spec/models/form/sales/pages/about_staircase_spec.rb +++ b/spec/models/form/sales/pages/about_staircase_spec.rb @@ -11,8 +11,24 @@ RSpec.describe Form::Sales::Pages::AboutStaircase, type: :model do expect(page.subsection).to eq(subsection) end - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[stairbought stairowned]) + describe "questions" do + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) } + + context "when 2022" do + let(:start_date) { Time.utc(2022, 2, 8) } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[stairbought stairowned]) + end + end + + context "when 2023" do + let(:start_date) { Time.utc(2023, 2, 8) } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[stairbought stairowned staircasesale]) + end + end end it "has the correct id" do diff --git a/spec/models/form/sales/questions/staircase_sale_spec.rb b/spec/models/form/sales/questions/staircase_sale_spec.rb new file mode 100644 index 000000000..39927c967 --- /dev/null +++ b/spec/models/form/sales/questions/staircase_sale_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::StaircaseSale, 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("staircasesale") + end + + it "has the correct header" do + expect(question.header).to eq("Is this transaction part of a back-to-back staircasing transaction to facilitate sale of the home on the open market?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Part of a back-to-back staircasing transaction") + 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 answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + "3" => { "value" => "Don't know" }, + }) + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq(nil) + end + + it "has the correct hint" do + expect(question.hint_text).to be_nil + end +end