gestionnaire: move commentaire creation into a service

This commit is contained in:
Pierre de La Morinerie 2018-09-04 16:19:29 +00:00
parent d31cc04b23
commit 750e1e0c83
4 changed files with 79 additions and 34 deletions

View file

@ -0,0 +1,17 @@
class CommentaireService
class << self
def create(sender, dossier, params)
attributes = params.merge(email: sender.email, dossier: dossier)
# If the user submits a empty message, simple_format will replace '' by '<p></p>',
# and thus bypass the not-empty constraint on commentaire's body.
#
# To avoid this, format the message only if a body is present in the first place.
if attributes[:body].present?
attributes[:body] = ActionController::Base.helpers.simple_format(attributes[:body])
end
Commentaire.new(attributes)
end
end
end