Browse Source

Add inferred question response

pull/907/head
Jack S 3 years ago
parent
commit
a9df0bfbd8
  1. 6
      app/models/form/question.rb
  2. 6
      app/models/form/sales/questions/buyer1_ethnic_group.rb
  3. 9
      spec/models/form/question_spec.rb

6
app/models/form/question.rb

@ -50,9 +50,11 @@ class Form::Question
answer = label_from_value(log[id]) if log[id].present?
answer_label = [prefix, format_value(answer), suffix_label(log)].join("") if answer
return answer_label if answer_label
has_inferred_check_answers_value?(log) ? inferred_check_answers_value["value"] : ""
inferred = inferred_check_answers_value["value"] if has_inferred_check_answers_value?(log)
return inferred if inferred.present?
answer_label
end
def get_inferred_answers(log)

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

@ -8,6 +8,12 @@ class Form::Sales::Questions::Buyer1EthnicGroup < ::Form::Question
@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."
@inferred_check_answers_value = {
"condition" => {
"ethnic_group" => 17,
},
"value" => "Prefers not to say",
}
end
ANSWER_OPTIONS = {

9
spec/models/form/question_spec.rb

@ -340,6 +340,15 @@ RSpec.describe Form::Question, type: :model do
expect(question.answer_label(lettings_log)).to eq("£500.00 every year")
end
end
context "with inferred_check_answers_value" do
let!(:sales_log) { FactoryBot.create(:sales_log, :completed, ethnic_group: 17) }
let(:question) { sales_log.form.get_question("ethnic_group", sales_log) }
it "returns the inferred label value" do
expect(question.answer_label(sales_log)).to eq("Prefers not to say")
end
end
end
describe ".completed?" do

Loading…
Cancel
Save