Browse Source

[CLDC-1484] Add buyer 1 questions to Sales form

pull/898/head
JS 3 years ago committed by Jack S
parent
commit
0c5dea5b44
  1. 11
      app/models/form/sales/questions/age1.rb
  2. 20
      app/models/form/sales/questions/buyer1_age_known.rb
  3. 6
      db/migrate/20220922084008_add_age1_to_sales_logs.rb
  4. 2
      db/schema.rb
  5. 41
      spec/models/form/sales/questions/age1_spec.rb
  6. 50
      spec/models/form/sales/questions/buyer1_age_known_spec.rb

11
app/models/form/sales/questions/age1.rb

@ -0,0 +1,11 @@
class Form::Sales::Questions::Age1 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "age1"
@check_answer_label = "Lead buyer’s age"
@header = "Age"
@type = "numeric"
@page = page
@width = 2
end
end

20
app/models/form/sales/questions/buyer1_age_known.rb

@ -0,0 +1,20 @@
class Form::Sales::Questions::Buyer1AgeKnown < ::Form::Question
def initialize(id, hsh, page)
super
@id = "age1_known"
@check_answer_label = "Buyer 1's age"
@header = "Do you know buyer 1's age?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "Buyer 1 is the person in the household who does the most paid work. If it's a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest."
@conditional_for = {
"age1" => [0],
}
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
end

6
db/migrate/20220922084008_add_age1_to_sales_logs.rb

@ -0,0 +1,6 @@
class AddAge1ToSalesLogs < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :age1, :integer
add_column :sales_logs, :age1_known, :integer
end
end

2
db/schema.rb

@ -336,6 +336,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_23_093628) do
t.integer "beds"
t.integer "jointmore"
t.integer "jointpur"
t.integer "age1"
t.integer "age1_known"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

41
spec/models/form/sales/questions/age1_spec.rb

@ -0,0 +1,41 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Age1, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
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("age1")
end
it "has the correct header" do
expect(question.header).to eq("Age")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Lead buyer’s age")
end
it "has the correct type" do
expect(question.type).to eq("numeric")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
it "has the correct width" do
expect(question.width).to eq(2)
end
end

50
spec/models/form/sales/questions/buyer1_age_known_spec.rb

@ -0,0 +1,50 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1AgeKnown, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
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("age1_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know buyer 1's age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1's age")
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 answer_options" do
expect(question.answer_options).to eq({
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age1" => [0],
})
end
it "has the correct hint" do
expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it's a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.")
end
end
Loading…
Cancel
Save