[#1563] Remove attestation mail attachment
This commit is contained in:
parent
e961df5481
commit
5ef129d960
6 changed files with 9 additions and 97 deletions
|
@ -106,18 +106,9 @@ module NewGestionnaire
|
|||
|
||||
dossier.save
|
||||
|
||||
# needed to force Carrierwave to provide dossier.attestation.pdf.read
|
||||
# when the Flipflop.remote_storage? is true, otherwise pdf.read is a closed stream.
|
||||
dossier.reload
|
||||
|
||||
attestation_pdf = nil
|
||||
if check_attestation_emailable
|
||||
attestation_pdf = dossier.attestation.pdf.read
|
||||
end
|
||||
|
||||
flash.notice = notice
|
||||
|
||||
NotificationMailer.send_notification(dossier, template, attestation_pdf).deliver_now!
|
||||
NotificationMailer.send_notification(dossier, template).deliver_now!
|
||||
|
||||
redirect_to gestionnaire_dossier_path(procedure, dossier)
|
||||
end
|
||||
|
@ -204,16 +195,6 @@ module NewGestionnaire
|
|||
])
|
||||
end
|
||||
|
||||
def check_attestation_emailable
|
||||
if dossier&.attestation&.emailable? == false
|
||||
human_size = number_to_human_size(dossier.attestation.pdf.size)
|
||||
msg = "the attestation of the dossier #{dossier.id} cannot be mailed because it is too heavy: #{human_size}"
|
||||
capture_message(msg, level: 'error')
|
||||
end
|
||||
|
||||
dossier&.attestation&.emailable?
|
||||
end
|
||||
|
||||
def mark_demande_as_read
|
||||
current_gestionnaire.mark_tab_as_seen(dossier, :demande)
|
||||
end
|
||||
|
|
|
@ -8,16 +8,12 @@ class NotificationMailer < ApplicationMailer
|
|||
send_notification(dossier, dossier.procedure.received_mail_template)
|
||||
end
|
||||
|
||||
def send_notification(dossier, mail_template, attestation = nil)
|
||||
def send_notification(dossier, mail_template)
|
||||
vars_mailer(dossier)
|
||||
|
||||
@subject = mail_template.subject_for_dossier dossier
|
||||
@body = mail_template.body_for_dossier dossier
|
||||
|
||||
if attestation.present?
|
||||
attachments['attestation.pdf'] = attestation
|
||||
end
|
||||
|
||||
mail(subject: @subject) { |format| format.html { @body } }
|
||||
end
|
||||
|
||||
|
|
|
@ -2,10 +2,4 @@ class Attestation < ApplicationRecord
|
|||
belongs_to :dossier
|
||||
|
||||
mount_uploader :pdf, AttestationUploader
|
||||
|
||||
MAX_SIZE_EMAILABLE = 2.megabytes
|
||||
|
||||
def emailable?
|
||||
pdf.size <= MAX_SIZE_EMAILABLE
|
||||
end
|
||||
end
|
||||
|
|
|
@ -152,7 +152,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
|||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(Mails::RefusedMail), nil).and_return(NotificationMailer)
|
||||
.with(dossier, kind_of(Mails::RefusedMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
|
@ -178,7 +178,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
|||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(Mails::WithoutContinuationMail), nil).and_return(NotificationMailer)
|
||||
.with(dossier, kind_of(Mails::WithoutContinuationMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
|
@ -188,14 +188,12 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context "with accepter" do
|
||||
let(:expected_attestation) { nil }
|
||||
|
||||
before do
|
||||
dossier.en_instruction!
|
||||
sign_in gestionnaire
|
||||
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(Mails::ClosedMail), expected_attestation)
|
||||
.with(dossier, kind_of(Mails::ClosedMail))
|
||||
.and_return(NotificationMailer)
|
||||
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
@ -220,34 +218,14 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
|||
before do
|
||||
attestation = Attestation.new
|
||||
allow(attestation).to receive(:pdf).and_return(double(read: 'pdf', size: 2.megabytes))
|
||||
allow(attestation).to receive(:emailable?).and_return(emailable)
|
||||
|
||||
expect_any_instance_of(Dossier).to receive(:reload)
|
||||
allow_any_instance_of(Dossier).to receive(:build_attestation).and_return(attestation)
|
||||
end
|
||||
|
||||
context 'emailable' do
|
||||
let(:emailable) { true }
|
||||
let(:expected_attestation) { 'pdf' }
|
||||
it 'The gestionnaire is sent back to the dossier page' do
|
||||
subject
|
||||
|
||||
it 'Notification email is sent with the attestation' do
|
||||
subject
|
||||
|
||||
is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the dossier has an attestation not emailable' do
|
||||
let(:emailable) { false }
|
||||
let(:expected_attestation) { nil }
|
||||
|
||||
it 'Notification email is sent without the attestation' do
|
||||
expect(controller).to receive(:capture_message)
|
||||
|
||||
subject
|
||||
|
||||
is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier)
|
||||
end
|
||||
is_expected.to redirect_to redirect_to gestionnaire_dossier_path(procedure, dossier)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -17,25 +17,11 @@ RSpec.describe NotificationMailer, type: :mailer do
|
|||
|
||||
describe '.send_notification' do
|
||||
let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') }
|
||||
let(:attestation) { nil }
|
||||
|
||||
subject { described_class.send_notification(dossier, email_template, attestation) }
|
||||
subject { described_class.send_notification(dossier, email_template) }
|
||||
|
||||
it { expect(subject.subject).to eq(email_template.subject_for_dossier) }
|
||||
it { expect(subject.body).to eq(email_template.body_for_dossier) }
|
||||
it { expect(subject.attachments['attestation.pdf']).to eq(nil) }
|
||||
|
||||
context 'when an attestation is provided' do
|
||||
let(:attestation) { 'attestation' }
|
||||
|
||||
it do
|
||||
expect(subject.attachments['attestation.pdf'].content_type)
|
||||
.to eq('application/pdf; filename=attestation.pdf')
|
||||
|
||||
expect(subject.attachments['attestation.pdf'].body).to eq('attestation')
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "create a commentaire not notified"
|
||||
end
|
||||
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
RSpec.describe Attestation, type: :model do
|
||||
describe 'emailable' do
|
||||
let(:attestation) do
|
||||
attestation = Attestation.new
|
||||
expect(attestation).to receive(:pdf).and_return(double(size: size))
|
||||
attestation
|
||||
end
|
||||
|
||||
subject { attestation.emailable? }
|
||||
|
||||
context 'when the pdf size is acceptable' do
|
||||
let(:size) { Attestation::MAX_SIZE_EMAILABLE }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when the pdf size is unacceptable' do
|
||||
let(:size) { Attestation::MAX_SIZE_EMAILABLE + 1 }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue