[#1110] Make linked procedure available to mail model
This commit is contained in:
parent
d80eb7a02b
commit
8d77cd58c6
10 changed files with 27 additions and 14 deletions
|
@ -41,9 +41,9 @@ module MailTemplateConcern
|
|||
end
|
||||
|
||||
module ClassMethods
|
||||
def default
|
||||
def default_for_procedure(procedure)
|
||||
body = ActionController::Base.new.render_to_string(template: self.const_get(:TEMPLATE_NAME))
|
||||
self.new(object: self.const_get(:DEFAULT_OBJECT), body: body)
|
||||
self.new(object: self.const_get(:DEFAULT_OBJECT), body: body, procedure: procedure)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ module Mails
|
|||
class ClosedMail < ApplicationRecord
|
||||
include MailTemplateConcern
|
||||
|
||||
belongs_to :procedure
|
||||
|
||||
SLUG = "closed_mail"
|
||||
TEMPLATE_NAME = "mails/closed_mail"
|
||||
DISPLAYED_NAME = "Accusé d'acceptation"
|
||||
|
|
|
@ -2,6 +2,8 @@ module Mails
|
|||
class InitiatedMail < ApplicationRecord
|
||||
include MailTemplateConcern
|
||||
|
||||
belongs_to :procedure
|
||||
|
||||
SLUG = "initiated_mail"
|
||||
TEMPLATE_NAME = "mails/initiated_mail"
|
||||
DISPLAYED_NAME = 'Accusé de réception'
|
||||
|
|
|
@ -2,6 +2,8 @@ module Mails
|
|||
class ReceivedMail < ApplicationRecord
|
||||
include MailTemplateConcern
|
||||
|
||||
belongs_to :procedure
|
||||
|
||||
SLUG = "received_mail"
|
||||
TEMPLATE_NAME = "mails/received_mail"
|
||||
DISPLAYED_NAME = 'Accusé de passage en instruction'
|
||||
|
|
|
@ -2,6 +2,8 @@ module Mails
|
|||
class RefusedMail < ApplicationRecord
|
||||
include MailTemplateConcern
|
||||
|
||||
belongs_to :procedure
|
||||
|
||||
SLUG = "refused_mail"
|
||||
TEMPLATE_NAME = "mails/refused_mail"
|
||||
DISPLAYED_NAME = 'Accusé de rejet du dossier'
|
||||
|
|
|
@ -2,6 +2,8 @@ module Mails
|
|||
class WithoutContinuationMail < ApplicationRecord
|
||||
include MailTemplateConcern
|
||||
|
||||
belongs_to :procedure
|
||||
|
||||
SLUG = "without_continuation"
|
||||
TEMPLATE_NAME = "mails/without_continuation_mail"
|
||||
DISPLAYED_NAME = 'Accusé de classement sans suite'
|
||||
|
|
|
@ -167,23 +167,23 @@ class Procedure < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def initiated_mail_template
|
||||
initiated_mail || Mails::InitiatedMail.default
|
||||
initiated_mail || Mails::InitiatedMail.default_for_procedure(self)
|
||||
end
|
||||
|
||||
def received_mail_template
|
||||
received_mail || Mails::ReceivedMail.default
|
||||
received_mail || Mails::ReceivedMail.default_for_procedure(self)
|
||||
end
|
||||
|
||||
def closed_mail_template
|
||||
closed_mail || Mails::ClosedMail.default
|
||||
closed_mail || Mails::ClosedMail.default_for_procedure(self)
|
||||
end
|
||||
|
||||
def refused_mail_template
|
||||
refused_mail || Mails::RefusedMail.default
|
||||
refused_mail || Mails::RefusedMail.default_for_procedure(self)
|
||||
end
|
||||
|
||||
def without_continuation_mail_template
|
||||
without_continuation_mail || Mails::WithoutContinuationMail.default
|
||||
without_continuation_mail || Mails::WithoutContinuationMail.default_for_procedure(self)
|
||||
end
|
||||
|
||||
def fields
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::MailTemplatesController, type: :controller do
|
||||
let(:initiated_mail) { Mails::InitiatedMail.default }
|
||||
let(:procedure) { create :procedure }
|
||||
let(:initiated_mail) { Mails::InitiatedMail.default_for_procedure(procedure) }
|
||||
|
||||
before do
|
||||
sign_in procedure.administrateur
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe MailTemplateConcern do
|
||||
let(:dossier) { create :dossier }
|
||||
let(:dossier2) { create :dossier }
|
||||
let(:initiated_mail) { Mails::InitiatedMail.default }
|
||||
let(:procedure) { create(:procedure)}
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:dossier2) { create(:dossier, procedure: procedure) }
|
||||
let(:initiated_mail) { Mails::InitiatedMail.default_for_procedure(procedure) }
|
||||
|
||||
shared_examples "can replace tokens in template" do
|
||||
describe 'with no token to replace' do
|
||||
|
|
|
@ -12,10 +12,12 @@ describe Procedure do
|
|||
end
|
||||
|
||||
describe 'initiated_mail' do
|
||||
subject { create(:procedure) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
subject { procedure }
|
||||
|
||||
context 'when initiated_mail is not customize' do
|
||||
it { expect(subject.initiated_mail_template.body).to eq(Mails::InitiatedMail.default.body) }
|
||||
it { expect(subject.initiated_mail_template.body).to eq(Mails::InitiatedMail.default_for_procedure(procedure).body) }
|
||||
end
|
||||
|
||||
context 'when initiated_mail is customize' do
|
||||
|
@ -209,7 +211,7 @@ describe Procedure do
|
|||
end
|
||||
|
||||
it 'should not duplicate default mail_template' do
|
||||
expect(subject.initiated_mail_template.attributes).to eq Mails::InitiatedMail.default.attributes
|
||||
expect(subject.initiated_mail_template.attributes).to eq Mails::InitiatedMail.default_for_procedure(subject).attributes
|
||||
end
|
||||
|
||||
it 'should not duplicate specific related objects' do
|
||||
|
|
Loading…
Add table
Reference in a new issue