[Fix #1454] Send weekly overview emails async, overview param is not correctly serialized by activejob so it is computed again when email is send
This commit is contained in:
parent
adffe1cd05
commit
0c6aa42f55
4 changed files with 7 additions and 6 deletions
|
@ -523,7 +523,7 @@ Performance/FlatMap:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Performance/HashEachMethods:
|
Performance/HashEachMethods:
|
||||||
Enabled: true
|
Enabled: false
|
||||||
|
|
||||||
Performance/LstripRstrip:
|
Performance/LstripRstrip:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
|
@ -7,7 +7,7 @@ class WeeklyOverviewJob < ApplicationJob
|
||||||
Gestionnaire.all
|
Gestionnaire.all
|
||||||
.map { |gestionnaire| [gestionnaire, gestionnaire.last_week_overview] }
|
.map { |gestionnaire| [gestionnaire, gestionnaire.last_week_overview] }
|
||||||
.reject { |_, overview| overview.nil? }
|
.reject { |_, overview| overview.nil? }
|
||||||
.each { |gestionnaire, overview| GestionnaireMailer.last_week_overview(gestionnaire, overview).deliver_now }
|
.each { |gestionnaire, _| GestionnaireMailer.last_week_overview(gestionnaire).deliver_later }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,9 @@ class GestionnaireMailer < ApplicationMailer
|
||||||
send_mail email, password, "Vous avez été nommé accompagnateur sur la plateforme TPS"
|
send_mail email, password, "Vous avez été nommé accompagnateur sur la plateforme TPS"
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_week_overview(gestionnaire, overview)
|
def last_week_overview(gestionnaire)
|
||||||
headers['X-mailjet-campaign'] = 'last_week_overview'
|
headers['X-mailjet-campaign'] = 'last_week_overview'
|
||||||
|
overview = gestionnaire.last_week_overview
|
||||||
send_mail gestionnaire.email, overview, 'Vos activités sur TPS'
|
send_mail gestionnaire.email, overview, 'Vos activités sur TPS'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ RSpec.describe WeeklyOverviewJob, type: :job do
|
||||||
describe 'perform' do
|
describe 'perform' do
|
||||||
let!(:gestionnaire) { create(:gestionnaire) }
|
let!(:gestionnaire) { create(:gestionnaire) }
|
||||||
let(:overview) { double('overview') }
|
let(:overview) { double('overview') }
|
||||||
let(:mailer_double) { double('mailer', deliver_now: true) }
|
let(:mailer_double) { double('mailer', deliver_later: true) }
|
||||||
|
|
||||||
context 'if the feature is enabled' do
|
context 'if the feature is enabled' do
|
||||||
before { allow(Features).to receive(:weekly_overview).and_return(true) }
|
before { allow(Features).to receive(:weekly_overview).and_return(true) }
|
||||||
|
@ -16,8 +16,8 @@ RSpec.describe WeeklyOverviewJob, type: :job do
|
||||||
WeeklyOverviewJob.new.perform
|
WeeklyOverviewJob.new.perform
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire, overview) }
|
it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire) }
|
||||||
it { expect(mailer_double).to have_received(:deliver_now) }
|
it { expect(mailer_double).to have_received(:deliver_later) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with one gestionnaire with no overviews' do
|
context 'with one gestionnaire with no overviews' do
|
||||||
|
|
Loading…
Reference in a new issue