Browse Source

Update nationality_all to use GlobalConstants for answer options and adjust displayed options

pull/3043/head
Manny Dinssa 4 weeks ago
parent
commit
daf2038693
  1. 6
      app/models/form/lettings/questions/nationality_all.rb
  2. 6
      app/models/form/sales/questions/nationality_all.rb
  3. 6
      spec/models/form/lettings/questions/nationality_all_spec.rb
  4. 6
      spec/models/form/sales/questions/nationality_all_spec.rb

6
app/models/form/lettings/questions/nationality_all.rb

@ -5,7 +5,7 @@ class Form::Lettings::Questions::NationalityAll < ::Form::Question
@copy_key = "lettings.household_characteristics.nationality_all.nationality_all" @copy_key = "lettings.household_characteristics.nationality_all.nationality_all"
@type = "select" @type = "select"
@check_answers_card_number = 1 @check_answers_card_number = 1
@answer_options = answer_options @answer_options = GlobalConstants::COUNTRIES_ANSWER_OPTIONS
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]
end end
@ -13,8 +13,8 @@ class Form::Lettings::Questions::NationalityAll < ::Form::Question
answer_options[log.nationality_all.to_s]["name"] answer_options[log.nationality_all.to_s]["name"]
end end
def answer_options def displayed_answer_options(_log, _current_user = nil)
GlobalConstants::COUNTRIES_ANSWER_OPTIONS.except("826") @answer_options.reject { |key, _| key == "826" }
end end
QUESTION_NUMBER_FROM_YEAR = { 2023 => 36, 2024 => 35 }.freeze QUESTION_NUMBER_FROM_YEAR = { 2023 => 36, 2024 => 35 }.freeze

6
app/models/form/sales/questions/nationality_all.rb

@ -2,7 +2,7 @@ class Form::Sales::Questions::NationalityAll < ::Form::Question
def initialize(id, hsh, page, buyer_index) def initialize(id, hsh, page, buyer_index)
super(id, hsh, page) super(id, hsh, page)
@type = "select" @type = "select"
@answer_options = answer_options @answer_options = GlobalConstants::COUNTRIES_ANSWER_OPTIONS
@check_answers_card_number = buyer_index @check_answers_card_number = buyer_index
@buyer_index = buyer_index @buyer_index = buyer_index
@question_number = QUESTION_NUMBER_FROM_YEAR_AND_BUYER_INDEX.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_BUYER_INDEX.max_by { |k, _v| k }.last)[buyer_index] @question_number = QUESTION_NUMBER_FROM_YEAR_AND_BUYER_INDEX.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_BUYER_INDEX.max_by { |k, _v| k }.last)[buyer_index]
@ -12,8 +12,8 @@ class Form::Sales::Questions::NationalityAll < ::Form::Question
answer_options[log.send(id).to_s]["name"] answer_options[log.send(id).to_s]["name"]
end end
def answer_options def displayed_answer_options(_log, _current_user = nil)
GlobalConstants::COUNTRIES_ANSWER_OPTIONS.except("826") @answer_options.reject { |key, _| key == "826" }
end end
QUESTION_NUMBER_FROM_YEAR_AND_BUYER_INDEX = { QUESTION_NUMBER_FROM_YEAR_AND_BUYER_INDEX = {

6
spec/models/form/lettings/questions/nationality_all_spec.rb

@ -18,6 +18,10 @@ RSpec.describe Form::Lettings::Questions::NationalityAll, type: :model do
end end
it "has the correct answer_options" do it "has the correct answer_options" do
expect(question.answer_options.count).to eq(202) expect(question.answer_options.count).to eq(203)
end
it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(nil, nil).count).to eq(202)
end end
end end

6
spec/models/form/sales/questions/nationality_all_spec.rb

@ -20,7 +20,11 @@ RSpec.describe Form::Sales::Questions::NationalityAll, type: :model do
end end
it "has the correct answer_options" do it "has the correct answer_options" do
expect(question.answer_options.count).to eq(202) expect(question.answer_options.count).to eq(203)
end
it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(nil, nil).count).to eq(202)
end end
it "has correct conditional for" do it "has correct conditional for" do

Loading…
Cancel
Save