Browse Source

When answer option is mapped just display directly

pull/373/head
baarkerlounger 3 years ago
parent
commit
9ae4e08ca6
  1. 18
      app/models/form/question.rb
  2. 12
      spec/models/form/question_spec.rb

18
app/models/form/question.rb

@ -104,14 +104,16 @@ class Form::Question
def label_from_value(value) def label_from_value(value)
return unless value return unless value
case type label = case type
when "radio" when "radio"
answer_options[value.to_s]["value"] labels = answer_options[value.to_s]
when "select" labels["value"] if labels
answer_options[value.to_s] when "select"
else answer_options[value.to_s]
value.to_s else
end value.to_s
end
label || value
end end
def value_is_yes?(value) def value_is_yes?(value)

12
spec/models/form/question_spec.rb

@ -115,6 +115,12 @@ RSpec.describe Form::Question, type: :model do
expect(question).to be_value_is_dont_know(7) expect(question).to be_value_is_dont_know(7)
end end
end end
context "when the saved answer is not in the value map" do
it "displays the saved answer umapped" do
expect(question.label_from_value(9999)).to eq(9999)
end
end
end end
context "when type is select" do context "when type is select" do
@ -130,6 +136,12 @@ RSpec.describe Form::Question, type: :model do
it "can map label from value" do it "can map label from value" do
expect(question.label_from_value("E06000014")).to eq("York") expect(question.label_from_value("E06000014")).to eq("York")
end end
context "when the saved answer is not in the value map" do
it "displays the saved answer umapped" do
expect(question.label_from_value(9999)).to eq(9999)
end
end
end end
context "when type is checkbox" do context "when type is checkbox" do

Loading…
Cancel
Save