Browse Source

Refactor working situation to take in person index

pull/1094/head
Kat 3 years ago
parent
commit
9ef39b86dd
  1. 14
      app/models/form/sales/pages/person.rb
  2. 21
      app/models/form/sales/pages/person_working_situation.rb
  3. 14
      app/models/form/sales/questions/person.rb
  4. 10
      app/models/form/sales/questions/person_working_situation.rb
  5. 16
      app/models/form/sales/subsections/household_characteristics.rb
  6. 12
      spec/models/form/sales/pages/person_working_situation_spec.rb
  7. 11
      spec/models/form/sales/questions/person_working_situation_spec.rb

14
app/models/form/sales/pages/person.rb

@ -0,0 +1,14 @@
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
end

21
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)
super
class Form::Sales::Pages::PersonWorkingSituation < Form::Sales::Pages::Person
def initialize(id, hsh, subsection, person_index)
super(id, hsh, subsection, person_index)
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_#{person_display_number(PERSON_INDEX)}" => 1, "jointpur" => joint_purchase? ? 1 : 2 },
{ "details_known_#{person_display_number}" => 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("ecstat#{@person_index}", nil, self, @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

14
app/models/form/sales/questions/person.rb

@ -0,0 +1,14 @@
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
end

10
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 = {

16
app/models/form/sales/subsections/household_characteristics.rb

@ -34,23 +34,23 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::PersonAge.new("person_1_age_joint_purchase", nil, self),
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, 2),
Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation_joint_purchase", nil, self, 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::PersonWorkingSituation.new("person_2_working_situation", nil, self, 3),
Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation_joint_purchase", nil, self, 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::PersonWorkingSituation.new("person_3_working_situation", nil, self, 4),
Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation_joint_purchase", nil, self, 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::PersonWorkingSituation.new("person_4_working_situation", nil, self, 5),
Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation_joint_purchase", nil, self, 6),
]
end
end

12
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

11
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")
@ -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")

Loading…
Cancel
Save