Browse Source

CLDC-1807 pluralise copy in housing benefits if joint purchase (#1320)

* alter copy conditionally for plurality depending on whether a purchase is a joint purchase

* correct linting oversight

* resolve rebase conflicts and alter annoying test to prevent future conflicts
pull/1350/head
Arthur Campbell 2 years ago committed by GitHub
parent
commit
80f04a8908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/form_controller.rb
  2. 9
      app/models/form/sales/pages/housing_benefits.rb
  3. 6
      app/models/form/sales/questions/housing_benefits.rb
  4. 3
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  5. 21
      spec/models/form/sales/pages/housing_benefits_spec.rb
  6. 17
      spec/models/form/sales/questions/housing_benefits_spec.rb
  7. 6
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
  8. 4
      spec/models/form_handler_spec.rb

2
app/controllers/form_controller.rb

@ -54,7 +54,7 @@ class FormController < ApplicationController
if @page.routed_to?(@log, current_user)
render "form/page"
else
redirect_to lettings_log_path(@log)
redirect_to @log.lettings? ? lettings_log_path(@log) : sales_log_path(@log)
end
else
render_not_found

9
app/models/form/sales/pages/housing_benefits.rb

@ -1,12 +1,13 @@
class Form::Sales::Pages::HousingBenefits < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "housing_benefits"
def initialize(id, hsh, subsection, joint_purchase:)
super(id, hsh, subsection)
@joint_purchase = joint_purchase
@depends_on = [{ "jointpur" => @joint_purchase ? 1 : 2 }]
end
def questions
@questions ||= [
Form::Sales::Questions::HousingBenefits.new(nil, nil, self),
Form::Sales::Questions::HousingBenefits.new(nil, nil, self, joint_purchase: @joint_purchase),
]
end
end

6
app/models/form/sales/questions/housing_benefits.rb

@ -1,9 +1,9 @@
class Form::Sales::Questions::HousingBenefits < ::Form::Question
def initialize(id, hsh, page)
super
def initialize(id, hsh, page, joint_purchase:)
super(id, hsh, page)
@id = "hb"
@check_answer_label = "Housing-related benefits buyer received before buying this property"
@header = "Was the buyer receiving any of these housing-related benefits immediately before buying this property?"
@header = "#{joint_purchase ? 'Were the buyers' : 'Was the buyer'} receiving any of these housing-related benefits immediately before buying this property?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
end

3
app/models/form/sales/subsections/income_benefits_and_savings.rb

@ -18,7 +18,8 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
Form::Sales::Pages::Buyer2IncomeValueCheck.new("buyer_2_income_value_check", nil, self),
Form::Sales::Pages::Buyer2Mortgage.new(nil, nil, self),
Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self, 2),
Form::Sales::Pages::HousingBenefits.new(nil, nil, self),
Form::Sales::Pages::HousingBenefits.new("housing_benefits_joint_purchase", nil, self, joint_purchase: true),
Form::Sales::Pages::HousingBenefits.new("housing_benefits_not_joint_purchase", nil, self, joint_purchase: false),
Form::Sales::Pages::Savings.new(nil, nil, self),
Form::Sales::Pages::SavingsValueCheck.new("savings_value_check", nil, self),
Form::Sales::Pages::DepositValueCheck.new("savings_deposit_value_check", nil, self),

21
spec/models/form/sales/pages/housing_benefits_spec.rb

@ -1,11 +1,12 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::HousingBenefits, 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) { "provided_id" }
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::HousingBenefits, type: :model do
end
it "has the correct id" do
expect(page.id).to eq("housing_benefits")
expect(page.id).to eq(page_id)
end
it "has the correct header" do
@ -27,7 +28,17 @@ RSpec.describe Form::Sales::Pages::HousingBenefits, type: :model do
expect(page.description).to be_nil
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
context "when joint_purchase is false" do
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "jointpur" => 2 }])
end
end
context "when joint_purchase is true" do
let(:joint_purchase) { true }
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "jointpur" => 1 }])
end
end
end

17
spec/models/form/sales/questions/housing_benefits_spec.rb

@ -1,11 +1,12 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::HousingBenefits, 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) { false }
it "has correct page" do
expect(question.page).to eq(page)
@ -15,8 +16,18 @@ RSpec.describe Form::Sales::Questions::HousingBenefits, type: :model do
expect(question.id).to eq("hb")
end
it "has the correct header" do
expect(question.header).to eq("Was the buyer receiving any of these housing-related benefits immediately before buying this property?")
context "when joint purchase is false" do
it "has the correct header" do
expect(question.header).to eq("Was the buyer receiving any of these housing-related benefits immediately before buying this property?")
end
end
context "when joint purchase is true" do
let(:joint_purchase) { true }
it "has the correct header" do
expect(question.header).to eq("Were the buyers receiving any of these housing-related benefits immediately before buying this property?")
end
end
it "has the correct check_answer_label" do

6
spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

@ -30,7 +30,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
buyer_2_income_value_check
buyer_2_mortgage
buyer_2_mortgage_value_check
housing_benefits
housing_benefits_joint_purchase
housing_benefits_not_joint_purchase
savings
savings_value_check
savings_deposit_value_check
@ -56,7 +57,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
buyer_2_income_value_check
buyer_2_mortgage
buyer_2_mortgage_value_check
housing_benefits
housing_benefits_joint_purchase
housing_benefits_not_joint_purchase
savings
savings_value_check
savings_deposit_value_check

4
spec/models/form_handler_spec.rb

@ -54,14 +54,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(182)
expect(form.pages.count).to be_positive
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(182)
expect(form.pages.count).to be_positive
expect(form.name).to eq("2021_2022_sales")
end
end

Loading…
Cancel
Save