2017-03-06 11:51:34 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MailTemplateConcern do
|
2017-10-20 10:32:28 +02:00
|
|
|
let(:dossier) { create :dossier }
|
|
|
|
let(:dossier2) { create :dossier }
|
|
|
|
let(:initiated_mail) { Mails::InitiatedMail.default }
|
|
|
|
|
|
|
|
shared_examples "can replace tokens in template" do
|
|
|
|
describe 'with no token to replace' do
|
|
|
|
let(:template) { '[TPS] rien à remplacer' }
|
|
|
|
it do
|
|
|
|
is_expected.to eq("[TPS] rien à remplacer")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with one token to replace' do
|
|
|
|
let(:template) { '[TPS] Dossier : --numero_dossier--' }
|
|
|
|
it do
|
|
|
|
is_expected.to eq("[TPS] Dossier : #{dossier.id}")
|
|
|
|
end
|
|
|
|
end
|
2017-03-06 11:51:34 +01:00
|
|
|
|
2017-10-20 10:32:28 +02:00
|
|
|
describe 'with multiples tokens to replace' do
|
|
|
|
let(:template) { '[TPS] --numero_dossier-- --libelle_procedure-- --lien_dossier--' }
|
|
|
|
it do
|
2017-03-06 11:51:34 +01:00
|
|
|
expected =
|
2017-04-12 11:18:28 +02:00
|
|
|
"[TPS] #{dossier.id} #{dossier.procedure.libelle} " +
|
2017-04-04 12:09:51 +02:00
|
|
|
"<a target=\"_blank\" href=\"http://localhost:3000/users/dossiers/#{dossier.id}/recapitulatif\">http://localhost:3000/users/dossiers/#{dossier.id}/recapitulatif</a>"
|
2017-03-06 11:51:34 +01:00
|
|
|
|
2017-10-20 10:32:28 +02:00
|
|
|
is_expected.to eq(expected)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.object_for_dossier' do
|
|
|
|
before { initiated_mail.object = template }
|
|
|
|
subject { initiated_mail.object_for_dossier(dossier) }
|
|
|
|
|
|
|
|
it_behaves_like "can replace tokens in template"
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.body_for_dossier' do
|
|
|
|
before { initiated_mail.body = template }
|
|
|
|
subject { initiated_mail.body_for_dossier(dossier) }
|
|
|
|
|
|
|
|
it_behaves_like "can replace tokens in template"
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.replace_tags' do
|
|
|
|
it "avoids side effects" do
|
|
|
|
subject = "n --numero_dossier--"
|
|
|
|
expect(initiated_mail.replace_tags(subject, dossier)).to eq("n #{dossier.id}")
|
|
|
|
expect(initiated_mail.replace_tags(subject, dossier2)).to eq("n #{dossier2.id}")
|
2017-03-06 11:51:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|