Remove ProcedureDecorator

This commit is contained in:
gregoirenovel 2018-12-27 13:29:39 +01:00 committed by Pierre de La Morinerie
parent b41764ec03
commit 9c130c41da
10 changed files with 31 additions and 61 deletions

View file

@ -1,25 +0,0 @@
class ProcedureDecorator < Draper::Decorator
delegate_all
def created_at_fr
created_at.strftime('%d/%m/%Y %H:%M')
end
def published_at_fr
if published_at.present?
published_at.strftime('%d/%m/%Y %H:%M')
end
end
def logo_img
if logo.blank?
h.image_url("marianne.svg")
else
if Flipflop.remote_storage?
(RemoteDownloader.new logo.filename).url
else
(LocalDownloader.new logo.path, 'logo').url
end
end
end
end

View file

@ -19,4 +19,18 @@ module ProcedureHelper
action = procedure.archivee? ? :reopen : :publish
t(action, scope: [:modal, :publish, key])
end
def logo_img(procedure)
logo = procedure.logo
if logo.blank?
ActionController::Base.helpers.image_url("marianne.svg")
else
if Flipflop.remote_storage?
RemoteDownloader.new(logo.filename).url
else
LocalDownloader.new(logo.path, 'logo').url
end
end
end
end

View file

@ -101,7 +101,7 @@
.col-md-6
%h4 Logo de la démarche
- if @procedure.logo.present?
= image_tag @procedure.decorate.logo_img, { style: 'height: 40px; display: inline; margin-right: 6px;', id: 'preview_procedure_logo' }
= image_tag logo_img(@procedure), { style: 'height: 40px; display: inline; margin-right: 6px;', id: 'preview_procedure_logo' }
\-
- if @procedure.persisted?

View file

@ -12,7 +12,7 @@
%th Actions
- @procedures.each do |procedure|
- procedure = procedure.decorate
- procedure = procedure
- admin_procedure_href = admin_procedure_path(procedure)
%tr{ id: "tr_dossier_#{procedure.id}", data: { href: admin_procedure_href } }
%td= link_to(procedure.id, admin_procedure_href)
@ -20,9 +20,9 @@
- if procedure.publiee?
%td.procedure-lien= link_to(procedure_lien(procedure), procedure_lien(procedure))
- if procedure.publiee_ou_archivee?
%td= link_to(procedure.published_at_fr, admin_procedure_href)
%td= link_to(published_at.present? ? published_at.strftime('%d/%m/%Y %H:%M') : "", admin_procedure_href)
- else
%td= link_to(procedure.created_at_fr, admin_procedure_href)
%td= link_to(procedure.created_at.strftime('%d/%m/%Y %H:%M'), admin_procedure_href)
%td
= link_to('Cloner', admin_procedure_clone_path(procedure.id), data: { method: :put }, class: 'btn-sm btn-primary clone-btn')
- if !procedure.publiee_ou_archivee?

View file

@ -1,7 +1,7 @@
#first-block
.en-cours
- if @procedure.logo.present?
= image_tag @procedure.decorate.logo_img, style: 'width: 30px;'
= image_tag logo_img(@procedure), style: 'width: 30px;'
%b
= @procedure.libelle

View file

@ -1,5 +1,5 @@
.procedure-logos
= image_tag procedure.decorate.logo_img
= image_tag logo_img(procedure)
- if procedure.euro_flag
= image_tag "flag_of_europe.svg"

View file

@ -8,7 +8,7 @@
= image_tag('drapeau_europe.png')
#logo_procedure.flag
= image_tag( @dossier.procedure.decorate.logo_img )
= image_tag(logo_img(dossier.procedure))
%h2#titre-procedure.text-info
= @dossier.procedure.libelle

View file

@ -13,7 +13,7 @@
.text-right
= link_to "Fermer", users_no_procedure_url, class: "link close-procedure"
.procedure-logos
= image_tag @dossier.procedure.decorate.logo_img
= image_tag logo_img(@dossier.procedure)
- if @dossier.procedure.euro_flag
= image_tag "flag_of_europe.svg"

View file

@ -1,28 +0,0 @@
require 'spec_helper'
describe ProcedureDecorator do
let(:published_at) { Time.zone.local(2017, 12, 24, 14, 12) }
let(:procedure) { create(:procedure, published_at: published_at, created_at: Time.zone.local(2015, 12, 24, 14, 10)) }
subject { procedure.decorate }
describe 'created_at_fr' do
subject { super().created_at_fr }
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("marianne.svg")}/) }
end
end

View file

@ -0,0 +1,9 @@
RSpec.describe ProcedureHelper, type: :helper do
let(:procedure) { create(:procedure) }
describe ".logo_img" do
subject { logo_img(procedure) }
it { is_expected.to match(/#{ActionController::Base.helpers.image_url("marianne.svg")}/) }
end
end