Browse Source

When answer option is mapped just display directly

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

6
app/models/form/question.rb

@ -104,14 +104,16 @@ class Form::Question
def label_from_value(value)
return unless value
case type
label = case type
when "radio"
answer_options[value.to_s]["value"]
labels = answer_options[value.to_s]
labels["value"] if labels
when "select"
answer_options[value.to_s]
else
value.to_s
end
label || value
end
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)
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
context "when type is select" do
@ -130,6 +136,12 @@ RSpec.describe Form::Question, type: :model do
it "can map label from value" do
expect(question.label_from_value("E06000014")).to eq("York")
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
context "when type is checkbox" do

Loading…
Cancel
Save