Browse Source

create new pages, questions, associated tests and a couple of boolean methods on sales log for depends_on readability

pull/1354/head
Arthur Campbell 3 years ago
parent
commit
d9b7416712
  1. 11
      app/models/form/sales/pages/buyer_2_living_in.rb
  2. 11
      app/models/form/sales/pages/buyer_2_previous_housing_situation.rb
  3. 17
      app/models/form/sales/questions/buyer_2_living_in.rb
  4. 23
      app/models/form/sales/questions/previous_tenure_buyer_2.rb
  5. 8
      app/models/sales_log.rb
  6. 31
      spec/models/form/sales/pages/buyer_2_living_in_spec.rb
  7. 31
      spec/models/form/sales/pages/buyer_2_previous_housing_situation_spec.rb
  8. 43
      spec/models/form/sales/questions/buyer_2_living_in_spec.rb
  9. 49
      spec/models/form/sales/questions/previous_tenure_buyer_2_spec.rb

11
app/models/form/sales/pages/buyer_2_living_in.rb

@ -0,0 +1,11 @@
class Form::Sales::Pages::Buyer2LivingIn < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_2_living_in"
@depends_on = [{ "buyer_two_will_live_in_property?" => true }]
end
def questions
@questions = [Form::Sales::Questions::Buyer2LivingIn.new(nil, nil, self)]
end
end

11
app/models/form/sales/pages/buyer_2_previous_housing_situation.rb

@ -0,0 +1,11 @@
class Form::Sales::Pages::Buyer2PreviousHousingSituation < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_2_previous_housing_situation"
@depends_on = [{ "buyer_two_not_already_living_in?" => true }]
end
def questions
@questions = [Form::Sales::Questions::PreviousTenureBuyer2.new(nil, nil, self)]
end
end

17
app/models/form/sales/questions/buyer_2_living_in.rb

@ -0,0 +1,17 @@
class Form::Sales::Questions::Buyer2LivingIn < ::Form::Question
def initialize(id, hsh, page)
super
@id = "buy2living"
@check_answer_label = "All buyers living at the same address"
@header = "Were all buyers living at the same address at the time of purchase?"
@type = "radio"
@hint_text = ""
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don't know" },
}.freeze
end

23
app/models/form/sales/questions/previous_tenure_buyer_2.rb

@ -0,0 +1,23 @@
class Form::Sales::Questions::PreviousTenureBuyer2 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "prevtenbuy2"
@check_answer_label = "Buyer 2’s previous tenure"
@header = "What was buyer 2’s previous tenure?"
@type = "radio"
@hint_text = ""
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = {
"1" => { "value" => "Local Authority" },
"2" => { "value" => "Private registered provider or housing association tenant" },
"3" => { "value" => "Private tenant" },
"5" => { "value" => "Owner occupier" },
"4" => { "value" => "Tied home or renting with job" },
"6" => { "value" => "Living with family or friends" },
"7" => { "value" => "Temporary accomodation" },
"9" => { "value" => "Other" },
"0" => { "value" => "Don't know" },
}.freeze
end

8
app/models/sales_log.rb

@ -151,6 +151,14 @@ class SalesLog < Log
inc1mort == 1
end
def buyer_two_will_live_in_property?
buy2livein == 1
end
def buyer_two_not_already_living_in?
buy2living == 2
end
def income2_used_for_mortgage?
inc2mort == 1
end

31
spec/models/form/sales/pages/buyer_2_living_in_spec.rb

@ -0,0 +1,31 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer2LivingIn, type: :model do
subject(:page) { described_class.new(nil, nil, subsection) }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[buy2living])
end
it "has the correct id" do
expect(page.id).to eq("buyer_2_living_in")
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "buyer_two_will_live_in_property?" => true }])
end
end

31
spec/models/form/sales/pages/buyer_2_previous_housing_situation_spec.rb

@ -0,0 +1,31 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer2PreviousHousingSituation, type: :model do
subject(:page) { described_class.new(nil, nil, subsection) }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[prevtenbuy2])
end
it "has the correct id" do
expect(page.id).to eq("buyer_2_previous_housing_situation")
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "buyer_two_not_already_living_in?" => true }])
end
end

43
spec/models/form/sales/questions/buyer_2_living_in_spec.rb

@ -0,0 +1,43 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer2LivingIn, type: :model do
subject(:question) { described_class.new(nil, nil, page) }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("buy2living")
end
it "has the correct header" do
expect(question.header).to eq("Were all buyers living at the same address at the time of purchase?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("All buyers living at the same address")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don't know" },
})
end
end

49
spec/models/form/sales/questions/previous_tenure_buyer_2_spec.rb

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::PreviousTenureBuyer2, type: :model do
subject(:question) { described_class.new(nil, nil, page) }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("prevtenbuy2")
end
it "has the correct header" do
expect(question.header).to eq("What was buyer 2’s previous tenure?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 2’s previous tenure")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Local Authority" },
"2" => { "value" => "Private registered provider or housing association tenant" },
"3" => { "value" => "Private tenant" },
"5" => { "value" => "Owner occupier" },
"4" => { "value" => "Tied home or renting with job" },
"6" => { "value" => "Living with family or friends" },
"7" => { "value" => "Temporary accomodation" },
"9" => { "value" => "Other" },
"0" => { "value" => "Don't know" },
})
end
end
Loading…
Cancel
Save