From a74ca8ad39ffb7f713ab88d9be8e2d6709562155 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 15 Nov 2021 14:55:35 +0100 Subject: [PATCH] fix(spec): scope out time as reference for time comparission, hope not a matter of precision --- app/models/commentaire.rb | 10 +++++++++- app/views/shared/dossiers/messages/_message.html.haml | 2 +- spec/services/commentaire_service_spec.rb | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index fbdf67b6f..a02a05cfe 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -47,6 +47,10 @@ class Commentaire < ApplicationRecord end end + def soft_deleted? + !!deleted_at + end + def header "#{redacted_email}, #{I18n.l(created_at, format: '%d %b %Y %H:%M')}" end @@ -79,6 +83,10 @@ class Commentaire < ApplicationRecord someone.present? && email == someone&.email end + def soft_deletable? + sent_by?(connected_user) && sent_by_instructeur? && !soft_deleted? + end + def file_url if piece_jointe.attached? && piece_jointe.virus_scanner.safe? Rails.application.routes.url_helpers.url_for(piece_jointe) @@ -99,7 +107,7 @@ class Commentaire < ApplicationRecord end def notify_user - DossierMailer.notify_new_answer(dossier, body).deliver_later + DossierMailer.notify_new_answer(dossier, body).deliver_later(wait: 10.minutes) end def messagerie_available? diff --git a/app/views/shared/dossiers/messages/_message.html.haml b/app/views/shared/dossiers/messages/_message.html.haml index f22a4f39a..3a84c9b91 100644 --- a/app/views/shared/dossiers/messages/_message.html.haml +++ b/app/views/shared/dossiers/messages/_message.html.haml @@ -11,7 +11,7 @@ .rich-text= pretty_commentaire(commentaire) .message-extras.flex.justify-start - - if commentaire.sent_by?(connected_user) && commentaire.sent_by_instructeur? && commentaire.deleted_at.nil? + - if commentaire.soft_deletable?(connected_user) = button_to instructeur_commentaire_path(commentaire.dossier.procedure, commentaire.dossier, commentaire), method: :delete, class: 'button danger', data: { confirm: t('views.shared.commentaires.destroy.confirm') } do %span.icon.delete = t('views.shared.commentaires.destroy.button') diff --git a/spec/services/commentaire_service_spec.rb b/spec/services/commentaire_service_spec.rb index 2864250e2..84b205e5e 100644 --- a/spec/services/commentaire_service_spec.rb +++ b/spec/services/commentaire_service_spec.rb @@ -103,8 +103,9 @@ describe CommentaireService do expect { subject }.to change { commentaire.reload.body }.from(an_instance_of(String)).to("Message supprimé") end it 'set deleted_at' do - Timecop.freeze do - expect { subject }.to change { commentaire.reload.deleted_at }.from(nil).to(Time.zone.now) + now = Time.zone.now + Timecop.freeze(now) do + expect { subject }.to change { commentaire.reload.deleted_at }.from(nil).to(now) end end end