Skip to content

Commit

Permalink
amelioration(mailer.logo): utilise procedure_logo_url pour afficher l…
Browse files Browse the repository at this point in the history
…e logo dans les mails
  • Loading branch information
Martin authored and mfo committed Aug 14, 2023
1 parent a3c6a2c commit bf6b5ea
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 27 deletions.
8 changes: 4 additions & 4 deletions app/mailers/dossier_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def notify_new_draft
@dossier = params[:dossier]
I18n.with_locale(@dossier.user_locale) do
@service = @dossier.procedure.service
@logo_url = @dossier.procedure.email_logo_url
@logo_url = procedure_logo_url(@dossier.procedure)
@subject = default_i18n_subject(libelle_demarche: @dossier.procedure.libelle)

mail(to: @dossier.user_email_for(:notification), subject: @subject) do |format|
Expand All @@ -27,7 +27,7 @@ def notify_new_answer
I18n.with_locale(dossier.user_locale) do
@dossier = dossier
@service = dossier.procedure.service
@logo_url = @dossier.procedure.email_logo_url
@logo_url = procedure_logo_url(@dossier.procedure)
@body = commentaire.body
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)

Expand All @@ -52,7 +52,7 @@ def notify_pending_correction
I18n.with_locale(dossier.user_locale) do
@dossier = dossier
@service = dossier.procedure.service
@logo_url = @dossier.procedure.email_logo_url
@logo_url = procedure_logo_url(@dossier.procedure)
@correction = commentaire.dossier_correction

@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
Expand Down Expand Up @@ -85,7 +85,7 @@ def notify_revert_to_instruction(dossier)
I18n.with_locale(dossier.user_locale) do
@dossier = dossier
@service = dossier.procedure.service
@logo_url = @dossier.procedure.email_logo_url
@logo_url = procedure_logo_url(@dossier.procedure)
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)

mail(to: dossier.user_email_for(:notification), subject: @subject) do |format|
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class NotificationMailer < ApplicationMailer

def send_notification
@service = @dossier.procedure.service
@logo_url = @dossier.procedure.email_logo_url
@logo_url = procedure_logo_url(@dossier.procedure)
attachments[@attachment[:filename]] = @attachment[:content] if @attachment.present?
I18n.with_locale(@dossier.user_locale) do
mail(subject: @subject, to: @email, template_name: 'send_notification')
Expand Down
8 changes: 0 additions & 8 deletions app/models/procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,6 @@ def missing_steps
result
end

def email_logo_url
if logo.attached?
logo.variant(:email).processed.blob.url(expires_in: 1.year)
else
ActionController::Base.helpers.image_url(PROCEDURE_DEFAULT_LOGO_SRC)
end
end

def logo_url
if logo.attached?
Rails.application.routes.url_helpers.url_for(logo)
Expand Down
14 changes: 0 additions & 14 deletions spec/models/procedure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1446,20 +1446,6 @@
end
end

describe '#email_logo_url' do
context 'with logo' do
let!(:procedure) { create(:procedure, :with_logo) }
it 'creates a blob synchronously one time' do
expect { procedure.email_logo_url }.to change { ActiveStorage::Blob.count }.by(1)
end

it 'creates the blob only the first time' do
procedure.email_logo_url
expect { procedure.email_logo_url }.not_to change { ActiveStorage::Blob.count }
end
end
end

describe '#average_dossier_weight' do
let(:procedure) { create(:procedure, :published) }

Expand Down

0 comments on commit bf6b5ea

Please sign in to comment.