From 114c0a64cb15e5dbb1e6566f059dcd07526eb1a0 Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Mon, 20 Feb 2023 14:37:32 +0000 Subject: [PATCH] update copy to handle pluralisation in the case of joint purchase for buyer previous, with associated testing changes --- app/models/form/sales/pages/buyer_previous.rb | 9 ++++--- .../form/sales/questions/buyer_previous.rb | 8 +++--- .../subsections/shared_ownership_scheme.rb | 3 ++- .../form/sales/pages/buyer_previous_spec.rb | 21 +++++++++++++--- .../sales/questions/buyer_previous_spec.rb | 25 +++++++++++++++---- .../shared_ownership_scheme_spec.rb | 3 ++- 6 files changed, 51 insertions(+), 18 deletions(-) diff --git a/app/models/form/sales/pages/buyer_previous.rb b/app/models/form/sales/pages/buyer_previous.rb index 361b3ba47..f37c6a847 100644 --- a/app/models/form/sales/pages/buyer_previous.rb +++ b/app/models/form/sales/pages/buyer_previous.rb @@ -1,12 +1,13 @@ class Form::Sales::Pages::BuyerPrevious < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "buyer_previous" + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) + @joint_purchase = joint_purchase + @depends_on = [{ "joint_purchase?" => joint_purchase }] end def questions @questions ||= [ - Form::Sales::Questions::BuyerPrevious.new(nil, nil, self), + Form::Sales::Questions::BuyerPrevious.new(nil, nil, self, joint_purchase: @joint_purchase), ] end end diff --git a/app/models/form/sales/questions/buyer_previous.rb b/app/models/form/sales/questions/buyer_previous.rb index 18ac019cb..d6c0c63d4 100644 --- a/app/models/form/sales/questions/buyer_previous.rb +++ b/app/models/form/sales/questions/buyer_previous.rb @@ -1,9 +1,9 @@ class Form::Sales::Questions::BuyerPrevious < ::Form::Question - def initialize(id, hsh, page) - super + def initialize(id, hsh, page, joint_purchase:) + super(id, hsh, page) @id = "soctenant" - @check_answer_label = "Buyer was a registered provider, housing association or local authority tenant immediately before this sale?" - @header = "Was the buyer a private registered provider, housing association or local authority tenant immediately before this sale?" + @check_answer_label = "#{joint_purchase ? 'Any buyers were' : 'Buyer was a'} registered provider#{'s' if joint_purchase}, housing association or local authority tenant#{'s' if joint_purchase} immediately before this sale?" + @header = "#{joint_purchase ? 'Were any of the buyers' : 'Was the buyer a'} private registered provider#{'s' if joint_purchase}, housing association or local authority tenant#{'s' if joint_purchase} immediately before this sale?" @type = "radio" @answer_options = ANSWER_OPTIONS end diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 40bca11be..1c30f3b6f 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -18,7 +18,8 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::HandoverDate.new(nil, nil, self), Form::Sales::Pages::HandoverDateCheck.new(nil, nil, self), Form::Sales::Pages::LaNominations.new(nil, nil, self), - Form::Sales::Pages::BuyerPrevious.new(nil, nil, self), + Form::Sales::Pages::BuyerPrevious.new("buyer_previous_joint_purchase", nil, self, joint_purchase: true), + Form::Sales::Pages::BuyerPrevious.new("buyer_previous_not_joint_purchase", nil, self, joint_purchase: false), Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self), Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self), Form::Sales::Pages::PreviousTenure.new(nil, nil, self), diff --git a/spec/models/form/sales/pages/buyer_previous_spec.rb b/spec/models/form/sales/pages/buyer_previous_spec.rb index a3355c137..e6dda073e 100644 --- a/spec/models/form/sales/pages/buyer_previous_spec.rb +++ b/spec/models/form/sales/pages/buyer_previous_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::BuyerPrevious, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase:) } - let(:page_id) { nil } + let(:page_id) { "example" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } + let(:joint_purchase) { false } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -16,7 +17,7 @@ RSpec.describe Form::Sales::Pages::BuyerPrevious, type: :model do end it "has the correct id" do - expect(page.id).to eq("buyer_previous") + expect(page.id).to eq("example") end it "has the correct header" do @@ -26,4 +27,18 @@ RSpec.describe Form::Sales::Pages::BuyerPrevious, type: :model do it "has the correct description" do expect(page.description).to be_nil end + + context "when sales is a joint purchase" do + let(:joint_purchase) { true } + + it "has the correct depends on" do + expect(page.depends_on).to eq([{ "joint_purchase?" => true }]) + end + end + + context "when sales is not a joint purchase" do + it "has the correct depends on" do + expect(page.depends_on).to eq([{ "joint_purchase?" => false }]) + end + end end diff --git a/spec/models/form/sales/questions/buyer_previous_spec.rb b/spec/models/form/sales/questions/buyer_previous_spec.rb index 07d3685f8..a1348f17b 100644 --- a/spec/models/form/sales/questions/buyer_previous_spec.rb +++ b/spec/models/form/sales/questions/buyer_previous_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::BuyerPrevious, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase:) } let(:question_id) { nil } let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } + let(:joint_purchase) { true } it "has correct page" do expect(question.page).to eq(page) @@ -15,12 +16,26 @@ RSpec.describe Form::Sales::Questions::BuyerPrevious, type: :model do expect(question.id).to eq("soctenant") end - it "has the correct header" do - expect(question.header).to eq("Was the buyer a private registered provider, housing association or local authority tenant immediately before this sale?") + context "when a joint purchase" do + it "has the correct header" do + expect(question.header).to eq("Were any of the buyers private registered providers, housing association or local authority tenants immediately before this sale?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Any buyers were registered providers, housing association or local authority tenants immediately before this sale?") + end end - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Buyer was a registered provider, housing association or local authority tenant immediately before this sale?") + context "when not a joint purchase" do + let(:joint_purchase) { false } + + it "has the correct header" do + expect(question.header).to eq("Was the buyer a private registered provider, housing association or local authority tenant immediately before this sale?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer was a registered provider, housing association or local authority tenant immediately before this sale?") + end end it "has the correct type" do 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 ef85e5ed2..3c189f93f 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -24,7 +24,8 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do handover_date handover_date_check la_nominations - buyer_previous + buyer_previous_joint_purchase + buyer_previous_not_joint_purchase previous_bedrooms previous_property_type shared_ownership_previous_tenure