Skip to content

Commit 425b5d5

Browse files
committed
refactor(mails): drop the write-only rich_body machinery
The Trix form was the only reader of the ActionText rich_body; with the tiptap editor in place, the copy-on-save callback and the attribute only produced dead writes. Existing action_text_rich_texts rows can be cleaned up later with a maintenance task.
1 parent 7cf0334 commit 425b5d5

3 files changed

Lines changed: 5 additions & 18 deletions

File tree

app/models/concerns/mail_template_concern.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ def attachment_for_dossier(dossier)
3535
nil
3636
end
3737

38-
def update_rich_body
39-
self.rich_body = self.body
40-
end
41-
4238
def tiptap_body
4339
json_body&.to_json
4440
end
@@ -77,9 +73,6 @@ def tiptap_subject_or_default
7773
end
7874

7975
included do
80-
has_rich_text :rich_body
81-
before_save :update_rich_body
82-
8376
validates :json_body, tags: true, if: -> { json_body.present? }
8477
validates :json_subject, tags: true, if: -> { json_subject.present? }
8578
validates :body, tags: true, if: -> { json_body.blank? }
@@ -89,9 +82,9 @@ def tiptap_subject_or_default
8982
class_methods do
9083
def default_for_procedure(procedure)
9184
template_name = default_template_name_for_procedure(procedure)
92-
rich_body = ActionController::Base.render(template: template_name).gsub(/<!--.*?-->/m, '')
93-
trix_rich_body = rich_body.gsub(/(?<!^|[.-])(?<!<\/strong>)\n/, ' ')
94-
new(subject: const_get(:DEFAULT_SUBJECT), body: trix_rich_body, rich_body: trix_rich_body, procedure: procedure)
85+
body = ActionController::Base.render(template: template_name).gsub(/<!--.*?-->/m, '')
86+
body = body.gsub(/(?<!^|[.-])(?<!<\/strong>)\n/, ' ')
87+
new(subject: const_get(:DEFAULT_SUBJECT), body:, procedure:)
9588
end
9689

9790
def default_template_name_for_procedure(procedure)

spec/models/concerns/mail_template_concern_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,6 @@
171171
end
172172
end
173173

174-
describe '#update_rich_body' do
175-
before { initiated_mail.update(body: "Voici le corps du mail") }
176-
177-
it { expect(initiated_mail.rich_body.to_plain_text).to eq(initiated_mail.body) }
178-
end
179-
180174
describe '#tiptap_inline_nodes_for' do
181175
it 'résout --numéro du dossier-- en mention' do
182176
nodes = mail.tiptap_inline_nodes_for('Dossier --numéro du dossier--')

spec/models/procedure_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
let(:procedure) { create(:procedure, attestation_acceptation_template: attestation_template) }
121121
let(:attestation_template) { nil }
122122

123-
subject { procedure.accepter_email_template.rich_body.body.to_html }
123+
subject { procedure.accepter_email_template.body }
124124

125125
context 'for procedures without an attestation' do
126126
it { is_expected.not_to include('lien attestation') }
@@ -147,7 +147,7 @@
147147
let(:procedure) { create(:procedure, attestation_refus_template: attestation_template) }
148148
let(:attestation_template) { nil }
149149

150-
subject { procedure.refuser_email_template.rich_body.body.to_html }
150+
subject { procedure.refuser_email_template.body }
151151

152152
context 'for procedures without an attestation' do
153153
it { is_expected.not_to include('lien attestation') }

0 commit comments

Comments
 (0)