From 333dbfe5bbe5dde2f8807be3c2652a10b378c1dd Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Thu, 6 Oct 2022 09:32:02 +0100 Subject: [PATCH] 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 --- .../pages/buyer2_relationship_to_buyer1.rb | 1 - .../buyer2_relationship_to_buyer1.rb | 10 ----- .../other_buyer2_relationship_to_buyer1.rb | 10 ----- ...50022_remove_otherrelat2_from_sales_log.rb | 5 +++ db/schema.rb | 5 +-- .../buyer2_relationship_to_buyer1_spec.rb | 2 +- .../buyer2_relationship_to_buyer1_spec.rb | 16 -------- ...ther_buyer2_relationship_to_buyer1_spec.rb | 37 ------------------- 8 files changed, 8 insertions(+), 78 deletions(-) delete mode 100644 app/models/form/sales/questions/other_buyer2_relationship_to_buyer1.rb create mode 100644 db/migrate/20221005150022_remove_otherrelat2_from_sales_log.rb delete mode 100644 spec/models/form/sales/questions/other_buyer2_relationship_to_buyer1_spec.rb diff --git a/app/models/form/sales/pages/buyer2_relationship_to_buyer1.rb b/app/models/form/sales/pages/buyer2_relationship_to_buyer1.rb index 7576e947c..8927ddd5a 100644 --- a/app/models/form/sales/pages/buyer2_relationship_to_buyer1.rb +++ b/app/models/form/sales/pages/buyer2_relationship_to_buyer1.rb @@ -13,7 +13,6 @@ class Form::Sales::Pages::Buyer2RelationshipToBuyer1 < ::Form::Page def questions @questions ||= [ Form::Sales::Questions::Buyer2RelationshipToBuyer1.new(nil, nil, self), - Form::Sales::Questions::OtherBuyer2RelationshipToBuyer1.new(nil, nil, self), ] end end diff --git a/app/models/form/sales/questions/buyer2_relationship_to_buyer1.rb b/app/models/form/sales/questions/buyer2_relationship_to_buyer1.rb index 67db6677d..11c9717ba 100644 --- a/app/models/form/sales/questions/buyer2_relationship_to_buyer1.rb +++ b/app/models/form/sales/questions/buyer2_relationship_to_buyer1.rb @@ -8,16 +8,6 @@ class Form::Sales::Questions::Buyer2RelationshipToBuyer1 < ::Form::Question @hint_text = "" @page = page @answer_options = ANSWER_OPTIONS - @conditional_for = { - "otherrelat2" => %w[X], - } - @hidden_in_check_answers = { - "depends_on" => [ - { - "relat2" => "X", - }, - ], - } end ANSWER_OPTIONS = { diff --git a/app/models/form/sales/questions/other_buyer2_relationship_to_buyer1.rb b/app/models/form/sales/questions/other_buyer2_relationship_to_buyer1.rb deleted file mode 100644 index f9959e3bd..000000000 --- a/app/models/form/sales/questions/other_buyer2_relationship_to_buyer1.rb +++ /dev/null @@ -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 diff --git a/db/migrate/20221005150022_remove_otherrelat2_from_sales_log.rb b/db/migrate/20221005150022_remove_otherrelat2_from_sales_log.rb new file mode 100644 index 000000000..9cc5a35cf --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index 1606ecbf3..58ca51de5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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 enable_extension "plpgsql" @@ -348,14 +348,13 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_05_125543) do t.integer "age2" t.integer "age2_known" t.string "relat2" - t.string "otherrelat2" t.string "sex2" t.integer "noint" t.integer "buy2livein" t.integer "ecstat2" t.integer "privacynotice" - t.integer "hholdcount" t.integer "ecstat1" + t.integer "hholdcount" 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" diff --git a/spec/models/form/sales/pages/buyer2_relationship_to_buyer1_spec.rb b/spec/models/form/sales/pages/buyer2_relationship_to_buyer1_spec.rb index 675913419..2e87764d6 100644 --- a/spec/models/form/sales/pages/buyer2_relationship_to_buyer1_spec.rb +++ b/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 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 it "has the correct id" do diff --git a/spec/models/form/sales/questions/buyer2_relationship_to_buyer1_spec.rb b/spec/models/form/sales/questions/buyer2_relationship_to_buyer1_spec.rb index cabd2168a..14bf2cb23 100644 --- a/spec/models/form/sales/questions/buyer2_relationship_to_buyer1_spec.rb +++ b/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" }, }) 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 diff --git a/spec/models/form/sales/questions/other_buyer2_relationship_to_buyer1_spec.rb b/spec/models/form/sales/questions/other_buyer2_relationship_to_buyer1_spec.rb deleted file mode 100644 index 1b4b3f91e..000000000 --- a/spec/models/form/sales/questions/other_buyer2_relationship_to_buyer1_spec.rb +++ /dev/null @@ -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