Browse Source

CLDC-2014 remove text field for buyer 1 nationality other (#1388)

* remove question no longer needed and associated test file

* amend page and the other question in that page that determined whether the deleted question should be shown
update associated test files

* createa a migration to remove the column for the deleted question

* update test broken by changes

* fix test broken by changes
pull/1409/head
Arthur Campbell 2 years ago committed by GitHub
parent
commit
4916049e18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/models/form/sales/pages/nationality1.rb
  2. 10
      app/models/form/sales/questions/nationality1.rb
  3. 10
      app/models/form/sales/questions/other_nationality1.rb
  4. 1
      app/services/imports/sales_logs_import_service.rb
  5. 5
      db/migrate/20230307111943_remove_othernational_from_sales_logs.rb
  6. 1
      db/schema.rb
  7. 12
      spec/features/form/conditional_questions_spec.rb
  8. 12
      spec/models/form/sales/pages/nationality1_spec.rb
  9. 30
      spec/models/form/sales/questions/nationality1_spec.rb
  10. 41
      spec/models/form/sales/questions/other_nationality1_spec.rb

7
app/models/form/sales/pages/nationality1.rb

@ -7,15 +7,12 @@ class Form::Sales::Pages::Nationality1 < ::Form::Page
"privacynotice" => 1, "privacynotice" => 1,
}, },
{ {
"noint" => 1, "buyer_not_interviewed?" => true,
}, },
] ]
end end
def questions def questions
@questions ||= [ @questions ||= [Form::Sales::Questions::Nationality1.new(nil, nil, self)]
Form::Sales::Questions::Nationality1.new(nil, nil, self),
Form::Sales::Questions::OtherNationality1.new(nil, nil, self),
]
end end
end end

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

@ -7,16 +7,6 @@ class Form::Sales::Questions::Nationality1 < ::Form::Question
@type = "radio" @type = "radio"
@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." @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."
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@conditional_for = {
"othernational" => [12],
}
@hidden_in_check_answers = {
"depends_on" => [
{
"national" => 12,
},
],
}
@check_answers_card_number = 1 @check_answers_card_number = 1
@inferred_check_answers_value = [{ @inferred_check_answers_value = [{
"condition" => { "condition" => {

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

@ -1,10 +0,0 @@
class Form::Sales::Questions::OtherNationality1 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "othernational"
@check_answer_label = "Buyer 1’s nationality"
@header = "Nationality"
@type = "text"
@check_answers_card_number = 1
end
end

1
app/services/imports/sales_logs_import_service.rb

@ -54,7 +54,6 @@ module Imports
attributes["details_known_#{index}"] = details_known(index, attributes) attributes["details_known_#{index}"] = details_known(index, attributes)
end end
attributes["national"] = unsafe_string_as_integer(xml_doc, "P1Nat") attributes["national"] = unsafe_string_as_integer(xml_doc, "P1Nat")
attributes["othernational"] = nil
attributes["ethnic"] = unsafe_string_as_integer(xml_doc, "P1Eth") attributes["ethnic"] = unsafe_string_as_integer(xml_doc, "P1Eth")
attributes["ethnic_group"] = ethnic_group(attributes["ethnic"]) attributes["ethnic_group"] = ethnic_group(attributes["ethnic"])
attributes["buy1livein"] = unsafe_string_as_integer(xml_doc, "LiveInBuyer1") attributes["buy1livein"] = unsafe_string_as_integer(xml_doc, "LiveInBuyer1")

5
db/migrate/20230307111943_remove_othernational_from_sales_logs.rb

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

1
db/schema.rb

@ -403,7 +403,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do
t.integer "age1_known" t.integer "age1_known"
t.string "sex1" t.string "sex1"
t.integer "national" t.integer "national"
t.string "othernational"
t.integer "ethnic" t.integer "ethnic"
t.integer "ethnic_group" t.integer "ethnic_group"
t.integer "buy1livein" t.integer "buy1livein"

12
spec/features/form/conditional_questions_spec.rb

@ -54,13 +54,13 @@ RSpec.describe "Form Conditional Questions" do
end end
it "gets cleared if the conditional question is hidden after editing the answer" do it "gets cleared if the conditional question is hidden after editing the answer" do
sales_log.update!(national: 12, othernational: "other") sales_log.update!(age1_known: 0, age1: 50)
visit("/sales-logs/#{sales_log.id}/buyer-1-nationality") visit("/sales-logs/#{sales_log.id}/buyer-1-age")
expect(page).to have_field("sales-log-othernational-field", with: "other") expect(page).to have_field("sales-log-age1-field", with: 50)
choose("sales-log-national-18-field", allow_label_click: true) choose("sales-log-age1-known-1-field", allow_label_click: true)
choose("sales-log-national-12-field", allow_label_click: true) choose("sales-log-age1-known-0-field", allow_label_click: true)
expect(page).to have_field("sales-log-othernational-field", with: "") expect(page).to have_field("sales-log-age1-field", with: "")
end end
end end
end end

12
spec/models/form/sales/pages/nationality1_spec.rb

@ -1,22 +1,20 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Pages::Nationality1, type: :model do RSpec.describe Form::Sales::Pages::Nationality1, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(nil, nil, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to be subsection
end end
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[national othernational]) expect(page.questions.map(&:id)).to eq %w[national]
end end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("buyer_1_nationality") expect(page.id).to eq "buyer_1_nationality"
end end
it "has the correct header" do it "has the correct header" do
@ -28,6 +26,6 @@ RSpec.describe Form::Sales::Pages::Nationality1, type: :model do
end end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq([{ "privacynotice" => 1 }, { "noint" => 1 }]) expect(page.depends_on).to eq [{ "privacynotice" => 1 }, { "buyer_not_interviewed?" => true }]
end end
end end

30
spec/models/form/sales/questions/nationality1_spec.rb

@ -1,30 +1,28 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::Nationality1, type: :model do RSpec.describe Form::Sales::Questions::Nationality1, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(nil, nil, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to be page
end end
it "has the correct id" do it "has the correct id" do
expect(question.id).to eq("national") expect(question.id).to eq "national"
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("What is buyer 1’s nationality?") expect(question.header).to eq "What is buyer 1’s nationality?"
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s nationality") expect(question.check_answer_label).to eq "Buyer 1’s nationality"
end end
it "has the correct type" do it "has the correct type" do
expect(question.type).to eq("radio") expect(question.type).to eq "radio"
end end
it "is not marked as derived" do it "is not marked as derived" do
@ -32,7 +30,7 @@ RSpec.describe Form::Sales::Questions::Nationality1, type: :model do
end end
it "has the correct hint" do 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.") 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
it "has the correct answer_options" do it "has the correct answer_options" do
@ -46,23 +44,15 @@ RSpec.describe Form::Sales::Questions::Nationality1, type: :model do
end end
it "has correct conditional for" do it "has correct conditional for" do
expect(question.conditional_for).to eq({ expect(question.conditional_for).to be_nil
"othernational" => [12],
})
end end
it "has correct hidden in check answers" do it "has correct hidden in check answers" do
expect(question.hidden_in_check_answers).to eq({ expect(question.hidden_in_check_answers).to be_nil
"depends_on" => [
{
"national" => 12,
},
],
})
end end
it "has the correct check_answers_card_number" do it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(1) expect(question.check_answers_card_number).to be 1
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do

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

@ -1,41 +0,0 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::OtherNationality1, 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("othernational")
end
it "has the correct header" do
expect(question.header).to eq("Nationality")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s nationality")
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
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(1)
end
end
Loading…
Cancel
Save