From aeae0c1806c9ed4a80a1b3d17243028a533fe120 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Mon, 18 Nov 2024 16:18:29 +0000 Subject: [PATCH] CLDC-3766: Ensure copy for sales Q78 is found correctly for 2024 logs (#2790) * CLDC-3766: Ensure copy for Q78 is found correctly * Fix tests --- app/models/form/sales/questions/staircase.rb | 2 +- app/models/form/sales/subsections/shared_ownership_scheme.rb | 1 + app/models/form/subsection.rb | 4 ++++ spec/models/form/sales/pages/staircase_spec.rb | 4 ++-- spec/models/form/sales/questions/staircase_spec.rb | 4 ++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/models/form/sales/questions/staircase.rb b/app/models/form/sales/questions/staircase.rb index 6c98397ff..d61456a8e 100644 --- a/app/models/form/sales/questions/staircase.rb +++ b/app/models/form/sales/questions/staircase.rb @@ -2,7 +2,7 @@ class Form::Sales::Questions::Staircase < ::Form::Question def initialize(id, hsh, page) super @id = "staircase" - @copy_key = "sales.#{page.subsection.id}.staircasing" + @copy_key = "sales.#{page.subsection.copy_key}.staircasing" @type = "radio" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] end diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 455755e31..f5d52153e 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -4,6 +4,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection @id = "shared_ownership_scheme" @label = "Shared ownership scheme" @depends_on = [{ "ownershipsch" => 1, "setup_completed?" => true }] + @copy_key = "sale_information" end def pages diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb index 25a473e98..3b74e29a5 100644 --- a/app/models/form/subsection.rb +++ b/app/models/form/subsection.rb @@ -14,6 +14,10 @@ class Form::Subsection delegate :form, to: :section + def copy_key + @copy_key ||= @id + end + def questions @questions ||= pages.flat_map(&:questions) end diff --git a/spec/models/form/sales/pages/staircase_spec.rb b/spec/models/form/sales/pages/staircase_spec.rb index 3c26181c2..6ce969ec2 100644 --- a/spec/models/form/sales/pages/staircase_spec.rb +++ b/spec/models/form/sales/pages/staircase_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Form::Sales::Pages::Staircase, type: :model do let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) } context "when start year is 2024" do - let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)), id: "sale_information") } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)), id: "shared_ownership_scheme", copy_key: "sale_information") } before do allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(false) @@ -32,7 +32,7 @@ RSpec.describe Form::Sales::Pages::Staircase, type: :model do end context "when start year is >= 2025" do - let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)), id: "setup") } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)), id: "setup", copy_key: "setup") } before do allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(true) diff --git a/spec/models/form/sales/questions/staircase_spec.rb b/spec/models/form/sales/questions/staircase_spec.rb index 29ba34d31..c9a9f44d8 100644 --- a/spec/models/form/sales/questions/staircase_spec.rb +++ b/spec/models/form/sales/questions/staircase_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Form::Sales::Questions::Staircase, type: :model do let(:question_definition) { nil } context "when start year is 2024" do - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1)), id: "sale_information")) } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1)), id: "shared_ownership_scheme", copy_key: "sale_information")) } before do allow(page.subsection.form).to receive(:start_year_2025_or_later?).and_return(false) @@ -43,7 +43,7 @@ RSpec.describe Form::Sales::Questions::Staircase, type: :model do end context "when start year is 2025" do - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 1)), id: "setup")) } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 1)), id: "setup", copy_key: "setup")) } before do allow(page.subsection.form).to receive(:start_year_2025_or_later?).and_return(true)