fix(spec): scope out time as reference for time comparission, hope not a matter of precision

This commit is contained in:
Martin 2021-11-15 14:55:35 +01:00
parent f1293814a3
commit a74ca8ad39
3 changed files with 13 additions and 4 deletions

View file

@ -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?

View file

@ -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')

View file

@ -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