Migrate mail body to ActionText
This commit is contained in:
parent
b34f8fbe3d
commit
d13b7f953f
3 changed files with 54 additions and 0 deletions
|
@ -11,6 +11,10 @@ module MailTemplateConcern
|
|||
replace_tags(body, dossier)
|
||||
end
|
||||
|
||||
included do
|
||||
has_rich_text :rich_body
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def default_for_procedure(procedure)
|
||||
template_name = default_template_name_for_procedure(procedure)
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: migrate_mail_body_to_actiontext'
|
||||
task migrate_mail_body_to_actiontext: :environment do
|
||||
puts "Running deploy task 'migrate_mail_body_to_actiontext'"
|
||||
|
||||
# Put your task implementation HERE.
|
||||
|
||||
[Mails::InitiatedMail, Mails::ReceivedMail, Mails::ClosedMail, Mails::WithoutContinuationMail, Mails::RefusedMail].each do |mt_class|
|
||||
progress = ProgressReport.new(mt_class.all.count)
|
||||
|
||||
mt_class.all.each do |mt|
|
||||
if mt.body.present?
|
||||
mt.rich_body = mt.body
|
||||
mt.save
|
||||
end
|
||||
progress.inc
|
||||
end
|
||||
|
||||
progress.finish
|
||||
end
|
||||
|
||||
# Update task as completed. If you remove the line below, the task will
|
||||
# run with every deploy (or every time you call after_party:run).
|
||||
AfterParty::TaskRecord.create version: '20190410131747'
|
||||
end # task :migrate_mail_body_to_actiontext
|
||||
end # namespace :after_party
|
|
@ -0,0 +1,24 @@
|
|||
describe '20190410131747_migrate_mail_body_to_actiontext.rake' do
|
||||
let(:rake_task) { Rake::Task['after_party:migrate_mail_body_to_actiontext'] }
|
||||
|
||||
let!(:closed_mail) { create(:closed_mail, body: body) }
|
||||
|
||||
before do
|
||||
rake_task.invoke
|
||||
closed_mail.reload
|
||||
end
|
||||
|
||||
after { rake_task.reenable }
|
||||
|
||||
context 'with a plain text body' do
|
||||
let(:body) { "Test de body" }
|
||||
|
||||
it { expect(closed_mail.rich_body.to_plain_text).to eq(closed_mail.body) }
|
||||
end
|
||||
|
||||
context 'with a html text body' do
|
||||
let(:body) { "Test de body<br>" }
|
||||
|
||||
it { expect(closed_mail.rich_body.to_s.squish).to eq("<div class=\"trix-content\"> #{closed_mail.body} </div>".squish) }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue