From d901852e09d63259fcfdb383723a064f23e0cda8 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 13 Dec 2017 17:00:24 +0100 Subject: [PATCH] Fix sentry issue #2139 when published_at is nil --- app/decorators/procedure_decorator.rb | 4 +++- spec/decorators/procedure_decorator_spec.rb | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/decorators/procedure_decorator.rb b/app/decorators/procedure_decorator.rb index 7ac4871db..9d0089b3e 100644 --- a/app/decorators/procedure_decorator.rb +++ b/app/decorators/procedure_decorator.rb @@ -10,7 +10,9 @@ class ProcedureDecorator < Draper::Decorator end def published_at_fr - published_at.localtime.strftime('%d/%m/%Y %H:%M') + if published_at.present? + published_at.localtime.strftime('%d/%m/%Y %H:%M') + end end def logo_img diff --git a/spec/decorators/procedure_decorator_spec.rb b/spec/decorators/procedure_decorator_spec.rb index 34ab7ceab..392ecc7dc 100644 --- a/spec/decorators/procedure_decorator_spec.rb +++ b/spec/decorators/procedure_decorator_spec.rb @@ -1,7 +1,10 @@ require 'spec_helper' describe ProcedureDecorator do - let(:procedure) { create(:procedure, :published, created_at: Time.new(2015, 12, 24, 14, 10)) } + let(:published_at) { Time.new(2017, 12, 24, 14, 12) } + let(:procedure) { create(:procedure, published_at: published_at, created_at: Time.new(2015, 12, 24, 14, 10)) } + let!(:procedure_path) { create(:procedure_path, administrateur: create(:administrateur), procedure: procedure) } + subject { procedure.decorate } describe 'lien' do @@ -14,6 +17,16 @@ describe ProcedureDecorator do it { is_expected.to eq('24/12/2015 14:10') } end + describe 'published_at_fr' do + subject { super().published_at_fr } + it { is_expected.to eq('24/12/2017 14:12') } + + context 'published_at is nil' do + let(:published_at) { nil } + it { is_expected.to eq(nil) } + end + end + describe 'logo_img' do subject { super().logo_img } it { is_expected.to match(/http.*#{ActionController::Base.helpers.image_url(LOGO_NAME)}/) }