From 9e288a7c3bbd08e5da76d64006a10b3cdaff1d5f Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Fri, 16 Dec 2022 09:30:04 +0000 Subject: [PATCH] Refactor out person classes (#1094) * Refactor working situation to take in person index * Refactor age to take in person index * Remove unused methods * Cleanup * Change person_index to a named argument * extract details_known_question_id * Fix answer options * Add field_for_person methods --- app/models/form/page.rb | 12 ------- app/models/form/question.rb | 12 ------- app/models/form/sales/pages/person.rb | 22 +++++++++++++ app/models/form/sales/pages/person_age.rb | 21 +++--------- .../sales/pages/person_working_situation.rb | 19 +++-------- app/models/form/sales/questions/person.rb | 18 +++++++++++ app/models/form/sales/questions/person_age.rb | 18 +++-------- .../form/sales/questions/person_age_known.rb | 24 +++++--------- .../questions/person_working_situation.rb | 20 ++++-------- .../subsections/household_characteristics.rb | 32 +++++++++---------- .../form/sales/pages/person_age_spec.rb | 11 ++++++- .../pages/person_working_situation_spec.rb | 12 ++++++- .../sales/questions/person_age_known_spec.rb | 11 ++++++- .../form/sales/questions/person_age_spec.rb | 11 ++++++- .../person_working_situation_spec.rb | 13 ++++++-- 15 files changed, 136 insertions(+), 120 deletions(-) create mode 100644 app/models/form/sales/pages/person.rb create mode 100644 app/models/form/sales/questions/person.rb diff --git a/app/models/form/page.rb b/app/models/form/page.rb index da70464bc..33e944eed 100644 --- a/app/models/form/page.rb +++ b/app/models/form/page.rb @@ -34,18 +34,6 @@ class Form::Page private - def person_database_number(person_index) - person_index[id] - end - - def person_display_number(person_index) - joint_purchase? ? person_index[id] - 2 : person_index[id] - 1 - end - - def joint_purchase? - id.include?("_joint_purchase") - end - def conditional_question_ids @conditional_question_ids ||= questions.flat_map { |q| next if q.conditional_for.blank? diff --git a/app/models/form/question.rb b/app/models/form/question.rb index c5121b123..5b4440e39 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -259,18 +259,6 @@ class Form::Question private - def person_database_number(person_index) - person_index[id] - end - - def person_display_number(person_index) - joint_purchase? ? person_index[id] - 2 : person_index[id] - 1 - end - - def joint_purchase? - page.id.include?("_joint_purchase") - end - def selected_answer_option_is_derived?(log) selected_option = answer_options&.dig(log[id].to_s.presence) selected_option.is_a?(Hash) && selected_option["depends_on"] && form.depends_on_met(selected_option["depends_on"], log) diff --git a/app/models/form/sales/pages/person.rb b/app/models/form/sales/pages/person.rb new file mode 100644 index 000000000..66e797cfa --- /dev/null +++ b/app/models/form/sales/pages/person.rb @@ -0,0 +1,22 @@ +class Form::Sales::Pages::Person < ::Form::Page + def initialize(id, hsh, subsection, person_index:) + super(id, hsh, subsection) + @person_index = person_index + end + + def person_display_number + joint_purchase? ? @person_index - 2 : @person_index - 1 + end + + def joint_purchase? + id.include?("_joint_purchase") + end + + def details_known_question_id + "details_known_#{person_display_number}" + end + + def field_for_person(field, suffix = "") + [field, @person_index, suffix].join + end +end diff --git a/app/models/form/sales/pages/person_age.rb b/app/models/form/sales/pages/person_age.rb index b25284685..ed5f4e954 100644 --- a/app/models/form/sales/pages/person_age.rb +++ b/app/models/form/sales/pages/person_age.rb @@ -1,29 +1,18 @@ -class Form::Sales::Pages::PersonAge < ::Form::Page - def initialize(id, hsh, subsection) +class Form::Sales::Pages::PersonAge < Form::Sales::Pages::Person + def initialize(id, hsh, subsection, person_index:) super @header = "" @description = "" @subsection = subsection @depends_on = [ - { "details_known_#{person_display_number(PERSON_INDEX)}" => 1, "jointpur" => joint_purchase? ? 1 : 2 }, + { details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }, ] end - PERSON_INDEX = { - "person_1_age" => 2, - "person_2_age" => 3, - "person_3_age" => 4, - "person_4_age" => 5, - "person_1_age_joint_purchase" => 3, - "person_2_age_joint_purchase" => 4, - "person_3_age_joint_purchase" => 5, - "person_4_age_joint_purchase" => 6, - }.freeze - def questions @questions ||= [ - Form::Sales::Questions::PersonAgeKnown.new("age#{person_database_number(PERSON_INDEX)}_known", nil, self), - Form::Sales::Questions::PersonAge.new("age#{person_database_number(PERSON_INDEX)}", nil, self), + Form::Sales::Questions::PersonAgeKnown.new(field_for_person("age", "_known"), nil, self, person_index: @person_index), + Form::Sales::Questions::PersonAge.new(field_for_person("age"), nil, self, person_index: @person_index), ] end end diff --git a/app/models/form/sales/pages/person_working_situation.rb b/app/models/form/sales/pages/person_working_situation.rb index 224ca4103..92d90423c 100644 --- a/app/models/form/sales/pages/person_working_situation.rb +++ b/app/models/form/sales/pages/person_working_situation.rb @@ -1,28 +1,17 @@ -class Form::Sales::Pages::PersonWorkingSituation < ::Form::Page - def initialize(id, hsh, subsection) +class Form::Sales::Pages::PersonWorkingSituation < Form::Sales::Pages::Person + def initialize(id, hsh, subsection, person_index:) super @header = "" @description = "" @subsection = subsection @depends_on = [ - { "details_known_#{person_display_number(PERSON_INDEX)}" => 1, "jointpur" => joint_purchase? ? 1 : 2 }, + { details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }, ] end def questions @questions ||= [ - Form::Sales::Questions::PersonWorkingSituation.new("ecstat#{person_database_number(PERSON_INDEX)}", nil, self), + Form::Sales::Questions::PersonWorkingSituation.new(field_for_person("ecstat"), nil, self, person_index: @person_index), ] end - - PERSON_INDEX = { - "person_1_working_situation" => 2, - "person_2_working_situation" => 3, - "person_3_working_situation" => 4, - "person_4_working_situation" => 5, - "person_1_working_situation_joint_purchase" => 3, - "person_2_working_situation_joint_purchase" => 4, - "person_3_working_situation_joint_purchase" => 5, - "person_4_working_situation_joint_purchase" => 6, - }.freeze end diff --git a/app/models/form/sales/questions/person.rb b/app/models/form/sales/questions/person.rb new file mode 100644 index 000000000..ebc280860 --- /dev/null +++ b/app/models/form/sales/questions/person.rb @@ -0,0 +1,18 @@ +class Form::Sales::Questions::Person < ::Form::Question + def initialize(id, hsh, page, person_index:) + super(id, hsh, page) + @person_index = person_index + end + + def person_display_number + joint_purchase? ? @person_index - 2 : @person_index - 1 + end + + def joint_purchase? + page.id.include?("_joint_purchase") + end + + def field_for_person(field, suffix = "") + [field, @person_index, suffix].join + end +end diff --git a/app/models/form/sales/questions/person_age.rb b/app/models/form/sales/questions/person_age.rb index 2e776b2d0..73dcce914 100644 --- a/app/models/form/sales/questions/person_age.rb +++ b/app/models/form/sales/questions/person_age.rb @@ -1,23 +1,15 @@ -class Form::Sales::Questions::PersonAge < ::Form::Question - def initialize(id, hsh, page) +class Form::Sales::Questions::PersonAge < Form::Sales::Questions::Person + def initialize(id, hsh, page, person_index:) super - @check_answer_label = "Person #{person_display_number(PERSON_INDEX)}’s age" + @check_answer_label = "Person #{person_display_number}’s age" @header = "Age" @type = "numeric" @page = page @width = 3 @inferred_check_answers_value = { - "condition" => { "age#{person_database_number(PERSON_INDEX)}_known" => 1 }, + "condition" => { field_for_person("age", "_known") => 1 }, "value" => "Not known", } - @check_answers_card_number = person_database_number(PERSON_INDEX) + @check_answers_card_number = person_index end - - PERSON_INDEX = { - "age2" => 2, - "age3" => 3, - "age4" => 4, - "age5" => 5, - "age6" => 6, - }.freeze end diff --git a/app/models/form/sales/questions/person_age_known.rb b/app/models/form/sales/questions/person_age_known.rb index be69a84c8..1b0643f7f 100644 --- a/app/models/form/sales/questions/person_age_known.rb +++ b/app/models/form/sales/questions/person_age_known.rb @@ -1,38 +1,30 @@ -class Form::Sales::Questions::PersonAgeKnown < ::Form::Question - def initialize(id, hsh, page) +class Form::Sales::Questions::PersonAgeKnown < ::Form::Sales::Questions::Person + def initialize(id, hsh, page, person_index:) super - @check_answer_label = "Person #{person_display_number(PERSON_INDEX)}’s age known?" - @header = "Do you know person #{person_display_number(PERSON_INDEX)}’s age?" + @check_answer_label = "Person #{person_display_number}’s age known?" + @header = "Do you know person #{person_display_number}’s age?" @type = "radio" @answer_options = ANSWER_OPTIONS @page = page @hint_text = "" @conditional_for = { - "age#{person_database_number(PERSON_INDEX)}" => [0], + field_for_person("age") => [0], } @hidden_in_check_answers = { "depends_on" => [ { - "age#{person_database_number(PERSON_INDEX)}_known" => 0, + field_for_person("age", "_known") => 0, }, { - "age#{person_database_number(PERSON_INDEX)}_known" => 1, + field_for_person("age", "_known") => 1, }, ], } - @check_answers_card_number = person_database_number(PERSON_INDEX) + @check_answers_card_number = @person_index end ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" }, }.freeze - - PERSON_INDEX = { - "age2_known" => 2, - "age3_known" => 3, - "age4_known" => 4, - "age5_known" => 5, - "age6_known" => 6, - }.freeze end diff --git a/app/models/form/sales/questions/person_working_situation.rb b/app/models/form/sales/questions/person_working_situation.rb index 8b16a54bc..6c48d1844 100644 --- a/app/models/form/sales/questions/person_working_situation.rb +++ b/app/models/form/sales/questions/person_working_situation.rb @@ -1,12 +1,12 @@ -class Form::Sales::Questions::PersonWorkingSituation < ::Form::Question - def initialize(id, hsh, page) +class Form::Sales::Questions::PersonWorkingSituation < ::Form::Sales::Questions::Person + def initialize(id, hsh, page, person_index:) super - @check_answer_label = "Person #{person_display_number(PERSON_INDEX)}’s working situation" - @header = "Which of these best describes Person #{person_display_number(PERSON_INDEX)}’s working situation?" + @check_answer_label = "Person #{person_display_number}’s working situation" + @header = "Which of these best describes Person #{person_display_number}’s working situation?" @type = "radio" @page = page @answer_options = ANSWER_OPTIONS - @check_answers_card_number = person_database_number(PERSON_INDEX) + @check_answers_card_number = person_index end ANSWER_OPTIONS = { @@ -18,16 +18,8 @@ class Form::Sales::Questions::PersonWorkingSituation < ::Form::Question "8" => { "value" => "Unable to work due to long term sick or disability" }, "5" => { "value" => "Retired" }, "0" => { "value" => "Other" }, - "10" => { "value" => "Buyer prefers not to say" }, + "10" => { "value" => "Person prefers not to say" }, "7" => { "value" => "Full-time student" }, "9" => { "value" => "Child under 16" }, }.freeze - - PERSON_INDEX = { - "ecstat2" => 2, - "ecstat3" => 3, - "ecstat4" => 4, - "ecstat5" => 5, - "ecstat6" => 6, - }.freeze end diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 7d6e6fb42..611e5cabd 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -30,27 +30,27 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self), Form::Sales::Pages::NumberOfOthersInProperty.new(nil, nil, self), Form::Sales::Pages::Person1Known.new(nil, nil, self), - Form::Sales::Pages::PersonAge.new("person_1_age", nil, self), - Form::Sales::Pages::PersonAge.new("person_1_age_joint_purchase", nil, self), + Form::Sales::Pages::PersonAge.new("person_1_age", nil, self, person_index: 2), + Form::Sales::Pages::PersonAge.new("person_1_age_joint_purchase", nil, self, person_index: 3), Form::Sales::Pages::Person1GenderIdentity.new(nil, nil, self), Form::Sales::Pages::Person1GenderIdentityJointPurchase.new(nil, nil, self), - Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation", nil, self), - Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation_joint_purchase", nil, self), + Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation", nil, self, person_index: 2), + Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation_joint_purchase", nil, self, person_index: 3), Form::Sales::Pages::Person2Known.new(nil, nil, self), - Form::Sales::Pages::PersonAge.new("person_2_age", nil, self), - Form::Sales::Pages::PersonAge.new("person_2_age_joint_purchase", nil, self), - Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation", nil, self), - Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation_joint_purchase", nil, self), + Form::Sales::Pages::PersonAge.new("person_2_age", nil, self, person_index: 3), + Form::Sales::Pages::PersonAge.new("person_2_age_joint_purchase", nil, self, person_index: 4), + Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation", nil, self, person_index: 3), + Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation_joint_purchase", nil, self, person_index: 4), Form::Sales::Pages::Person3Known.new(nil, nil, self), - Form::Sales::Pages::PersonAge.new("person_3_age", nil, self), - Form::Sales::Pages::PersonAge.new("person_3_age_joint_purchase", nil, self), - Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation", nil, self), - Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation_joint_purchase", nil, self), + Form::Sales::Pages::PersonAge.new("person_3_age", nil, self, person_index: 4), + Form::Sales::Pages::PersonAge.new("person_3_age_joint_purchase", nil, self, person_index: 5), + Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation", nil, self, person_index: 4), + Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation_joint_purchase", nil, self, person_index: 5), Form::Sales::Pages::Person4Known.new(nil, nil, self), - Form::Sales::Pages::PersonAge.new("person_4_age", nil, self), - Form::Sales::Pages::PersonAge.new("person_4_age_joint_purchase", nil, self), - Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation", nil, self), - Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation_joint_purchase", nil, self), + Form::Sales::Pages::PersonAge.new("person_4_age", nil, self, person_index: 5), + Form::Sales::Pages::PersonAge.new("person_4_age_joint_purchase", nil, self, person_index: 6), + Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation", nil, self, person_index: 5), + Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation_joint_purchase", nil, self, person_index: 6), ] end end diff --git a/spec/models/form/sales/pages/person_age_spec.rb b/spec/models/form/sales/pages/person_age_spec.rb index 21255e80e..0ee4ab777 100644 --- a/spec/models/form/sales/pages/person_age_spec.rb +++ b/spec/models/form/sales/pages/person_age_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::PersonAge, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } + subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) } let(:page_id) { "person_1_age" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } + let(:person_index) { 1 } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -22,6 +23,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do context "with a non joint purchase" do context "and person 1" do let(:page_id) { "person_1_age" } + let(:person_index) { 2 } it "has correct questions" do expect(page.questions.map(&:id)).to eq(%w[age2_known age2]) @@ -42,6 +44,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do context "and person 2" do let(:page_id) { "person_2_age" } + let(:person_index) { 3 } it "has correct questions" do expect(page.questions.map(&:id)).to eq(%w[age3_known age3]) @@ -62,6 +65,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do context "and person 3" do let(:page_id) { "person_3_age" } + let(:person_index) { 4 } it "has correct questions" do expect(page.questions.map(&:id)).to eq(%w[age4_known age4]) @@ -82,6 +86,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do context "and person 4" do let(:page_id) { "person_4_age" } + let(:person_index) { 5 } it "has correct questions" do expect(page.questions.map(&:id)).to eq(%w[age5_known age5]) @@ -104,6 +109,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do context "with joint purchase" do context "and person 1" do let(:page_id) { "person_1_age_joint_purchase" } + let(:person_index) { 3 } it "has correct questions" do expect(page.questions.map(&:id)).to eq(%w[age3_known age3]) @@ -124,6 +130,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do context "and person 2" do let(:page_id) { "person_2_age_joint_purchase" } + let(:person_index) { 4 } it "has correct questions" do expect(page.questions.map(&:id)).to eq(%w[age4_known age4]) @@ -144,6 +151,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do context "and person 3" do let(:page_id) { "person_3_age_joint_purchase" } + let(:person_index) { 5 } it "has correct questions" do expect(page.questions.map(&:id)).to eq(%w[age5_known age5]) @@ -164,6 +172,7 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do context "and person 4" do let(:page_id) { "person_4_age_joint_purchase" } + let(:person_index) { 6 } it "has correct questions" do expect(page.questions.map(&:id)).to eq(%w[age6_known age6]) diff --git a/spec/models/form/sales/pages/person_working_situation_spec.rb b/spec/models/form/sales/pages/person_working_situation_spec.rb index d1b13b8c1..65bdb42d0 100644 --- a/spec/models/form/sales/pages/person_working_situation_spec.rb +++ b/spec/models/form/sales/pages/person_working_situation_spec.rb @@ -1,10 +1,11 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } + subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } + let(:person_index) { 1 } context "without joint purchase" do let(:page_id) { "person_1_working_situation" } @@ -22,6 +23,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do end context "with person 1" do + let(:person_index) { 2 } let(:page_id) { "person_1_working_situation" } it "has correct questions" do @@ -38,6 +40,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do end context "with person 2" do + let(:person_index) { 3 } let(:page_id) { "person_2_working_situation" } it "has correct questions" do @@ -54,6 +57,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do end context "with person 3" do + let(:person_index) { 4 } let(:page_id) { "person_3_working_situation" } it "has correct questions" do @@ -70,6 +74,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do end context "with person 4" do + let(:person_index) { 5 } let(:page_id) { "person_4_working_situation" } it "has correct questions" do @@ -102,6 +107,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do end context "with person 1" do + let(:person_index) { 3 } let(:page_id) { "person_1_working_situation_joint_purchase" } it "has correct questions" do @@ -118,6 +124,8 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do end context "with person 2" do + let(:person_index) { 4 } + let(:page_id) { "person_2_working_situation_joint_purchase" } it "has correct questions" do @@ -134,6 +142,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do end context "with person 3" do + let(:person_index) { 5 } let(:page_id) { "person_3_working_situation_joint_purchase" } it "has correct questions" do @@ -150,6 +159,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do end context "with person 4" do + let(:person_index) { 6 } let(:page_id) { "person_4_working_situation_joint_purchase" } it "has correct questions" do diff --git a/spec/models/form/sales/questions/person_age_known_spec.rb b/spec/models/form/sales/questions/person_age_known_spec.rb index d7e6e1a2a..2cc760fc5 100644 --- a/spec/models/form/sales/questions/person_age_known_spec.rb +++ b/spec/models/form/sales/questions/person_age_known_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, person_index:) } let(:question_id) { "age3_known" } let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } + let(:person_index) { 2 } before do allow(page).to receive(:id).and_return("person_1_age") @@ -37,6 +38,7 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do context "with a non joint purchase" do context "and person 1" do let(:question_id) { "age2_known" } + let(:person_index) { 2 } before do allow(page).to receive(:id).and_return("person_1_age") @@ -82,6 +84,7 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do context "and person 2" do let(:question_id) { "age3_known" } + let(:person_index) { 3 } before do allow(page).to receive(:id).and_return("person_2_age") @@ -127,6 +130,7 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do context "and person 3" do let(:question_id) { "age4_known" } + let(:person_index) { 4 } before do allow(page).to receive(:id).and_return("person_3_age") @@ -172,6 +176,7 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do context "and person 4" do let(:question_id) { "age5_known" } + let(:person_index) { 5 } before do allow(page).to receive(:id).and_return("person_4_age") @@ -219,6 +224,7 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do context "with a joint purchase" do context "and person 1" do let(:question_id) { "age3_known" } + let(:person_index) { 3 } before do allow(page).to receive(:id).and_return("person_1_age_joint_purchase") @@ -264,6 +270,7 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do context "and person 2" do let(:question_id) { "age4_known" } + let(:person_index) { 4 } before do allow(page).to receive(:id).and_return("person_2_age_joint_purchase") @@ -309,6 +316,7 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do context "and person 3" do let(:question_id) { "age5_known" } + let(:person_index) { 5 } before do allow(page).to receive(:id).and_return("person_3_age_joint_purchase") @@ -354,6 +362,7 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do context "and person 4" do let(:question_id) { "age6_known" } + let(:person_index) { 6 } before do allow(page).to receive(:id).and_return("person_4_age_joint_purchase") diff --git a/spec/models/form/sales/questions/person_age_spec.rb b/spec/models/form/sales/questions/person_age_spec.rb index 3db41e806..b1eacfed5 100644 --- a/spec/models/form/sales/questions/person_age_spec.rb +++ b/spec/models/form/sales/questions/person_age_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::PersonAge, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, person_index:) } let(:question_id) { "age3" } let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } + let(:person_index) { 2 } before do allow(page).to receive(:id).and_return("person_1_age") @@ -33,6 +34,7 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do context "with not a joint purchase" do context "and person 1" do + let(:person_index) { 2 } let(:question_id) { "age2" } before do @@ -64,6 +66,7 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do end context "and person 2" do + let(:person_index) { 3 } let(:question_id) { "age3" } before do @@ -95,6 +98,7 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do end context "and person 3" do + let(:person_index) { 4 } let(:question_id) { "age4" } before do @@ -126,6 +130,7 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do end context "and person 4" do + let(:person_index) { 5 } let(:question_id) { "age5" } before do @@ -159,6 +164,7 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do context "with a joint purchase" do context "and person 1" do + let(:person_index) { 3 } let(:question_id) { "age3" } before do @@ -190,6 +196,7 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do end context "and person 2" do + let(:person_index) { 4 } let(:question_id) { "age4" } before do @@ -221,6 +228,7 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do end context "and person 3" do + let(:person_index) { 5 } let(:question_id) { "age5" } before do @@ -252,6 +260,7 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do end context "and person 4" do + let(:person_index) { 6 } let(:question_id) { "age6" } before do diff --git a/spec/models/form/sales/questions/person_working_situation_spec.rb b/spec/models/form/sales/questions/person_working_situation_spec.rb index 7c19b058d..a8beb49d1 100644 --- a/spec/models/form/sales/questions/person_working_situation_spec.rb +++ b/spec/models/form/sales/questions/person_working_situation_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, person_index:) } let(:question_id) { "ecstat2" } let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } + let(:person_index) { 2 } before do allow(page).to receive(:id).and_return("person_1_working_situation") @@ -37,7 +38,7 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do "8" => { "value" => "Unable to work due to long term sick or disability" }, "5" => { "value" => "Retired" }, "0" => { "value" => "Other" }, - "10" => { "value" => "Buyer prefers not to say" }, + "10" => { "value" => "Person prefers not to say" }, "7" => { "value" => "Full-time student" }, "9" => { "value" => "Child under 16" }, }) @@ -46,6 +47,7 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do context "when person 1" do context "and not joint purchase" do let(:question_id) { "ecstat2" } + let(:person_index) { 2 } before do allow(page).to receive(:id).and_return("person_1_working_situation") @@ -69,6 +71,7 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do end context "and joint purchase" do + let(:person_index) { 3 } let(:question_id) { "ecstat3" } before do @@ -96,6 +99,7 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do context "when person 2" do context "and not joint purchase" do let(:question_id) { "ecstat3" } + let(:person_index) { 3 } before do allow(page).to receive(:id).and_return("person_2_working_situation") @@ -120,6 +124,7 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do context "and joint purchase" do let(:question_id) { "ecstat4" } + let(:person_index) { 4 } before do allow(page).to receive(:id).and_return("person_2_working_situation_joint_purchase") @@ -146,6 +151,7 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do context "when person 3" do context "and not joint purchase" do let(:question_id) { "ecstat4" } + let(:person_index) { 4 } before do allow(page).to receive(:id).and_return("person_3_working_situation") @@ -170,6 +176,7 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do context "and joint purchase" do let(:question_id) { "ecstat5" } + let(:person_index) { 5 } before do allow(page).to receive(:id).and_return("person_3_working_situation_joint_purchase") @@ -196,6 +203,7 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do context "when person 4" do context "and not joint purchase" do let(:question_id) { "ecstat5" } + let(:person_index) { 5 } before do allow(page).to receive(:id).and_return("person_4_working_situation") @@ -220,6 +228,7 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do context "and joint purchase" do let(:question_id) { "ecstat6" } + let(:person_index) { 6 } before do allow(page).to receive(:id).and_return("person_4_working_situation_joint_purchase")