Don’t use alias_method_chain, use a proxy method
This commit is contained in:
parent
bc7fc2634e
commit
ec69086ebc
7 changed files with 38 additions and 41 deletions
|
@ -19,11 +19,11 @@ class Admin::MailTemplatesController < AdminController
|
|||
|
||||
def mail_templates
|
||||
[
|
||||
@procedure.initiated_mail,
|
||||
@procedure.received_mail,
|
||||
@procedure.closed_mail,
|
||||
@procedure.refused_mail,
|
||||
@procedure.without_continuation_mail
|
||||
@procedure.initiated_mail_template,
|
||||
@procedure.received_mail_template,
|
||||
@procedure.closed_mail_template,
|
||||
@procedure.refused_mail_template,
|
||||
@procedure.without_continuation_mail_template
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
dossier.received!
|
||||
flash.notice = 'Dossier considéré comme reçu.'
|
||||
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.received_mail).deliver_now!
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.received_mail_template).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
@ -112,7 +112,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
dossier.next_step! 'gestionnaire', 'refuse'
|
||||
flash.notice = 'Dossier considéré comme refusé.'
|
||||
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.refused_mail).deliver_now!
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.refused_mail_template).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
@ -125,7 +125,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
dossier.next_step! 'gestionnaire', 'without_continuation'
|
||||
flash.notice = 'Dossier considéré comme sans suite.'
|
||||
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.without_continuation_mail).deliver_now!
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.without_continuation_mail_template).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
@ -138,7 +138,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
dossier.next_step! 'gestionnaire', 'close'
|
||||
flash.notice = 'Dossier traité avec succès.'
|
||||
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.closed_mail).deliver_now!
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.closed_mail_template).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
|
|
@ -52,7 +52,7 @@ class Users::DescriptionController < UsersController
|
|||
else
|
||||
if dossier.draft?
|
||||
dossier.initiated!
|
||||
NotificationMailer.send_notification(dossier, procedure.initiated_mail).deliver_now!
|
||||
NotificationMailer.send_notification(dossier, procedure.initiated_mail_template).deliver_now!
|
||||
end
|
||||
flash.notice = 'Félicitations, votre demande a bien été enregistrée.'
|
||||
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: dossier.id)
|
||||
|
|
|
@ -99,11 +99,11 @@ class Procedure < ActiveRecord::Base
|
|||
procedure.logo_secure_token = nil
|
||||
procedure.remote_logo_url = self.logo_url
|
||||
|
||||
procedure.initiated_mail = initiated_mail_without_override.try(:dup)
|
||||
procedure.received_mail = received_mail_without_override.try(:dup)
|
||||
procedure.closed_mail = closed_mail_without_override.try(:dup)
|
||||
procedure.refused_mail = refused_mail_without_override.try(:dup)
|
||||
procedure.without_continuation_mail = without_continuation_mail_without_override.try(:dup)
|
||||
procedure.initiated_mail = initiated_mail.try(:dup)
|
||||
procedure.received_mail = received_mail.try(:dup)
|
||||
procedure.closed_mail = closed_mail.try(:dup)
|
||||
procedure.refused_mail = refused_mail.try(:dup)
|
||||
procedure.without_continuation_mail = without_continuation_mail.try(:dup)
|
||||
|
||||
return procedure if procedure.save
|
||||
end
|
||||
|
@ -137,28 +137,23 @@ class Procedure < ActiveRecord::Base
|
|||
ProcedureOverview.new(self, start_date, notifications_count)
|
||||
end
|
||||
|
||||
def initiated_mail_with_override
|
||||
self.initiated_mail_without_override || Mails::InitiatedMail.default
|
||||
def initiated_mail_template
|
||||
initiated_mail || Mails::InitiatedMail.default
|
||||
end
|
||||
alias_method_chain "initiated_mail", :override
|
||||
|
||||
def received_mail_with_override
|
||||
self.received_mail_without_override || Mails::ReceivedMail.default
|
||||
def received_mail_template
|
||||
received_mail || Mails::ReceivedMail.default
|
||||
end
|
||||
alias_method_chain "received_mail", :override
|
||||
|
||||
def closed_mail_with_override
|
||||
self.closed_mail_without_override || Mails::ClosedMail.default
|
||||
def closed_mail_template
|
||||
closed_mail || Mails::ClosedMail.default
|
||||
end
|
||||
alias_method_chain "closed_mail", :override
|
||||
|
||||
def refused_mail_with_override
|
||||
self.refused_mail_without_override || Mails::RefusedMail.default
|
||||
def refused_mail_template
|
||||
refused_mail || Mails::RefusedMail.default
|
||||
end
|
||||
alias_method_chain "refused_mail", :override
|
||||
|
||||
def without_continuation_mail_with_override
|
||||
self.without_continuation_mail_without_override || Mails::WithoutContinuationMail.default
|
||||
def without_continuation_mail_template
|
||||
without_continuation_mail || Mails::WithoutContinuationMail.default
|
||||
end
|
||||
alias_method_chain "without_continuation_mail", :override
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ describe Admin::MailTemplatesController, type: :controller do
|
|||
it { expect(response).to redirect_to admin_procedure_mail_templates_path(procedure) }
|
||||
|
||||
context 'the mail template' do
|
||||
subject { procedure.reload ; procedure.initiated_mail }
|
||||
subject { procedure.reload ; procedure.initiated_mail_template }
|
||||
|
||||
it { expect(subject.object).to eq(object) }
|
||||
it { expect(subject.body).to eq(body) }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class NotificationMailerPreview < ActionMailer::Preview
|
||||
|
||||
def send_notification
|
||||
NotificationMailer.send_notification(Dossier.last, Dossier.last.procedure.initiated_mail)
|
||||
NotificationMailer.send_notification(Dossier.last, Dossier.last.procedure.initiated_mail_template)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,18 +2,20 @@ require 'spec_helper'
|
|||
|
||||
describe Procedure do
|
||||
describe 'mail templates' do
|
||||
it { expect(subject.initiated_mail).to be_a(Mails::InitiatedMail) }
|
||||
it { expect(subject.received_mail).to be_a(Mails::ReceivedMail) }
|
||||
it { expect(subject.closed_mail).to be_a(Mails::ClosedMail) }
|
||||
it { expect(subject.refused_mail).to be_a(Mails::RefusedMail) }
|
||||
it { expect(subject.without_continuation_mail).to be_a(Mails::WithoutContinuationMail) }
|
||||
subject { create(:procedure) }
|
||||
|
||||
it { expect(subject.initiated_mail_template).to be_a(Mails::InitiatedMail) }
|
||||
it { expect(subject.received_mail_template).to be_a(Mails::ReceivedMail) }
|
||||
it { expect(subject.closed_mail_template).to be_a(Mails::ClosedMail) }
|
||||
it { expect(subject.refused_mail_template).to be_a(Mails::RefusedMail) }
|
||||
it { expect(subject.without_continuation_mail_template).to be_a(Mails::WithoutContinuationMail) }
|
||||
end
|
||||
|
||||
describe 'initiated_mail' do
|
||||
subject { create(:procedure) }
|
||||
|
||||
context 'when initiated_mail is not customize' do
|
||||
it { expect(subject.initiated_mail.body).to eq(Mails::InitiatedMail.default.body) }
|
||||
it { expect(subject.initiated_mail_template.body).to eq(Mails::InitiatedMail.default.body) }
|
||||
end
|
||||
|
||||
context 'when initiated_mail is customize' do
|
||||
|
@ -22,7 +24,7 @@ describe Procedure do
|
|||
subject.save
|
||||
subject.reload
|
||||
end
|
||||
it { expect(subject.initiated_mail.body).to eq('sisi') }
|
||||
it { expect(subject.initiated_mail_template.body).to eq('sisi') }
|
||||
end
|
||||
|
||||
context 'when initiated_mail is customize ... again' do
|
||||
|
@ -31,7 +33,7 @@ describe Procedure do
|
|||
subject.save
|
||||
subject.reload
|
||||
end
|
||||
it { expect(subject.initiated_mail.body).to eq('toto') }
|
||||
it { expect(subject.initiated_mail_template.body).to eq('toto') }
|
||||
|
||||
it { expect(Mails::InitiatedMail.count).to eq(1) }
|
||||
end
|
||||
|
@ -185,7 +187,7 @@ describe Procedure do
|
|||
end
|
||||
|
||||
it 'should not duplicate default mail_template' do
|
||||
expect(subject.initiated_mail.attributes).to eq Mails::InitiatedMail.default.attributes
|
||||
expect(subject.initiated_mail_template.attributes).to eq Mails::InitiatedMail.default.attributes
|
||||
end
|
||||
|
||||
it 'should not duplicate specific related objects' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue