From 7f4e6eae6b20c1b0cc49036d6151ccddf7713b39 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Mon, 7 May 2018 12:24:05 +0200 Subject: [PATCH] No dubious proc. email == Everything is ok || Something went wrong. We should always send dubious procedure email. --- app/jobs/find_dubious_procedures_job.rb | 4 +--- .../dubious_procedures.html.haml | 15 +++++++++------ spec/jobs/find_dubious_procedures_job_spec.rb | 8 +++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/jobs/find_dubious_procedures_job.rb b/app/jobs/find_dubious_procedures_job.rb index 9cc4f8ba3..ecfb3b56c 100644 --- a/app/jobs/find_dubious_procedures_job.rb +++ b/app/jobs/find_dubious_procedures_job.rb @@ -24,8 +24,6 @@ class FindDubiousProceduresJob < ApplicationJob .group_by(&:procedure_id) .map { |_procedure_id, tdcs| [tdcs[0].procedure, tdcs] } - if dubious_procedures_and_tdcs.present? - AdministrationMailer.dubious_procedures(dubious_procedures_and_tdcs).deliver_now - end + AdministrationMailer.dubious_procedures(dubious_procedures_and_tdcs).deliver_now end end diff --git a/app/views/administration_mailer/dubious_procedures.html.haml b/app/views/administration_mailer/dubious_procedures.html.haml index f7ce22024..2f90561c2 100644 --- a/app/views/administration_mailer/dubious_procedures.html.haml +++ b/app/views/administration_mailer/dubious_procedures.html.haml @@ -1,8 +1,11 @@ - content_for(:title, 'Liste de procédures douteuses') -%ul - - @procedures_and_type_de_champs.each do |procedure, type_de_champs| - %li - = link_to "Nº #{procedure.id},", manager_procedure_url(procedure) -  #{procedure.libelle} : - %b= type_de_champs.map(&:libelle).join(', ') +- if @procedures_and_type_de_champs.any? + %ul + - @procedures_and_type_de_champs.each do |procedure, type_de_champs| + %li + = link_to "Nº #{procedure.id},", manager_procedure_url(procedure) +  #{procedure.libelle} : + %b= type_de_champs.map(&:libelle).join(', ') +- else + Il n'y a aucune procédure douteuse aujourd'hui diff --git a/spec/jobs/find_dubious_procedures_job_spec.rb b/spec/jobs/find_dubious_procedures_job_spec.rb index d03de6bfc..e8b354f99 100644 --- a/spec/jobs/find_dubious_procedures_job_spec.rb +++ b/spec/jobs/find_dubious_procedures_job_spec.rb @@ -30,25 +30,27 @@ RSpec.describe FindDubiousProceduresJob, type: :job do expect(receive_procedure).to eq(procedure) expect(receive_forbidden_tdcs).to match(forbidden_tdcs) + + expect(AdministrationMailer).to have_received(:dubious_procedures).with(@dubious_procedures_args) end context 'and a whitelisted procedure' do let(:procedure) { create(:procedure, whitelisted_at: DateTime.now) } - it { expect(AdministrationMailer).not_to have_received(:dubious_procedures) } + it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) } end context 'and a archived procedure' do let(:procedure) { create(:procedure, archived_at: DateTime.now) } - it { expect(AdministrationMailer).not_to have_received(:dubious_procedures) } + it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) } end end context 'with no suspicious champs' do let(:tdcs) { [allowed_tdc] } - it { expect(AdministrationMailer).not_to receive(:dubious_procedures) } + it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) } end end end