Browse Source

Fix date bug

pull/235/head
baarkerlounger 3 years ago
parent
commit
c8bba428b5
  1. 2
      app/models/form/question.rb
  2. 5
      spec/models/form/question_spec.rb

2
app/models/form/question.rb

@ -35,7 +35,7 @@ class Form::Question
def answer_label(case_log) def answer_label(case_log)
return checkbox_answer_label(case_log) if type == "checkbox" return checkbox_answer_label(case_log) if type == "checkbox"
return case_log[id].to_formatted_s(:govuk_date) if type == "date" return case_log[id]&.to_formatted_s(:govuk_date).to_s if type == "date"
return case_log[id].to_s if case_log[id].present? return case_log[id].to_s if case_log[id].present?

5
spec/models/form/question_spec.rb

@ -120,6 +120,11 @@ RSpec.describe Form::Question, type: :model do
case_log.mrcdate = Time.zone.local(2021, 10, 11) case_log.mrcdate = Time.zone.local(2021, 10, 11)
expect(subject.answer_label(case_log)).to eq("11 October 2021") expect(subject.answer_label(case_log)).to eq("11 October 2021")
end end
it "can handle nils" do
case_log.mrcdate = nil
expect(subject.answer_label(case_log)).to eq("")
end
end end
context "when type is checkbox" do context "when type is checkbox" do

Loading…
Cancel
Save