Browse Source

Cldc 1522 buyer 2 relationship (#936)

* feat: add buyer 2-1 relationship question and page (migration and schema to come in next commit)

* feat: add buyer 2-1 migration and schema

* feat: update schema

* feat: add depends_on and tests

* feat: add hint text

* tests: add new tests

* refactor: lint appeasing

* test: update no. of pages

* feat: remove text input for Other option

* feat: update schema
pull/935/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
333dbfe5bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/form/sales/pages/buyer2_relationship_to_buyer1.rb
  2. 10
      app/models/form/sales/questions/buyer2_relationship_to_buyer1.rb
  3. 10
      app/models/form/sales/questions/other_buyer2_relationship_to_buyer1.rb
  4. 5
      db/migrate/20221005150022_remove_otherrelat2_from_sales_log.rb
  5. 5
      db/schema.rb
  6. 2
      spec/models/form/sales/pages/buyer2_relationship_to_buyer1_spec.rb
  7. 16
      spec/models/form/sales/questions/buyer2_relationship_to_buyer1_spec.rb
  8. 37
      spec/models/form/sales/questions/other_buyer2_relationship_to_buyer1_spec.rb

1
app/models/form/sales/pages/buyer2_relationship_to_buyer1.rb

@ -13,7 +13,6 @@ class Form::Sales::Pages::Buyer2RelationshipToBuyer1 < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Questions::Buyer2RelationshipToBuyer1.new(nil, nil, self), Form::Sales::Questions::Buyer2RelationshipToBuyer1.new(nil, nil, self),
Form::Sales::Questions::OtherBuyer2RelationshipToBuyer1.new(nil, nil, self),
] ]
end end
end end

10
app/models/form/sales/questions/buyer2_relationship_to_buyer1.rb

@ -8,16 +8,6 @@ class Form::Sales::Questions::Buyer2RelationshipToBuyer1 < ::Form::Question
@hint_text = "" @hint_text = ""
@page = page @page = page
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@conditional_for = {
"otherrelat2" => %w[X],
}
@hidden_in_check_answers = {
"depends_on" => [
{
"relat2" => "X",
},
],
}
end end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {

10
app/models/form/sales/questions/other_buyer2_relationship_to_buyer1.rb

@ -1,10 +0,0 @@
class Form::Sales::Questions::OtherBuyer2RelationshipToBuyer1 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "otherrelat2"
@check_answer_label = "Buyer 2's relationship to buyer 1"
@header = "Buyer 2's relationship to buyer 1"
@type = "text"
@page = page
end
end

5
db/migrate/20221005150022_remove_otherrelat2_from_sales_log.rb

@ -0,0 +1,5 @@
class RemoveOtherrelat2FromSalesLog < ActiveRecord::Migration[7.0]
def change
remove_column :sales_logs, :otherrelat2, :string
end
end

5
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_10_05_125543) do ActiveRecord::Schema[7.0].define(version: 2022_10_05_150022) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -348,14 +348,13 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_05_125543) do
t.integer "age2" t.integer "age2"
t.integer "age2_known" t.integer "age2_known"
t.string "relat2" t.string "relat2"
t.string "otherrelat2"
t.string "sex2" t.string "sex2"
t.integer "noint" t.integer "noint"
t.integer "buy2livein" t.integer "buy2livein"
t.integer "ecstat2" t.integer "ecstat2"
t.integer "privacynotice" t.integer "privacynotice"
t.integer "hholdcount"
t.integer "ecstat1" t.integer "ecstat1"
t.integer "hholdcount"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" 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 ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

2
spec/models/form/sales/pages/buyer2_relationship_to_buyer1_spec.rb

@ -12,7 +12,7 @@ RSpec.describe Form::Sales::Pages::Buyer2RelationshipToBuyer1, type: :model do
end end
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[relat2 otherrelat2]) expect(page.questions.map(&:id)).to eq(%w[relat2])
end end
it "has the correct id" do it "has the correct id" do

16
spec/models/form/sales/questions/buyer2_relationship_to_buyer1_spec.rb

@ -43,20 +43,4 @@ RSpec.describe Form::Sales::Questions::Buyer2RelationshipToBuyer1, type: :model
"R" => { "value" => "Buyer prefers not to say" }, "R" => { "value" => "Buyer prefers not to say" },
}) })
end end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"otherrelat2" => %w[X],
})
end
it "has correct hidden in check answers" do
expect(question.hidden_in_check_answers).to eq({
"depends_on" => [
{
"relat2" => "X",
},
],
})
end
end end

37
spec/models/form/sales/questions/other_buyer2_relationship_to_buyer1_spec.rb

@ -1,37 +0,0 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::OtherBuyer2RelationshipToBuyer1, 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("otherrelat2")
end
it "has the correct header" do
expect(question.header).to eq("Buyer 2's relationship to buyer 1")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 2's relationship to buyer 1")
end
it "has the correct type" do
expect(question.type).to eq("text")
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
end
Loading…
Cancel
Save