2017-05-12 17:41:03 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe WeeklyOverviewWorker, type: :worker do
|
|
|
|
describe 'perform' do
|
|
|
|
let!(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
let(:overview) { double('overview') }
|
|
|
|
let(:mailer_double) { double('mailer', deliver_now: true) }
|
|
|
|
|
2017-05-19 16:21:11 +02:00
|
|
|
context 'if the feature is enabled' do
|
|
|
|
before { allow(Features).to receive(:weekly_overview).and_return(true) }
|
|
|
|
|
|
|
|
context 'with one gestionnaire with one overview' do
|
|
|
|
before :each do
|
|
|
|
expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(overview)
|
|
|
|
allow(GestionnaireMailer).to receive(:last_week_overview).and_return(mailer_double)
|
|
|
|
WeeklyOverviewWorker.new.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire, overview) }
|
|
|
|
it { expect(mailer_double).to have_received(:deliver_now) }
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
|
2017-05-19 16:21:11 +02:00
|
|
|
context 'with one gestionnaire with no overviews' do
|
|
|
|
before :each do
|
|
|
|
expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(nil)
|
|
|
|
allow(GestionnaireMailer).to receive(:last_week_overview)
|
|
|
|
WeeklyOverviewWorker.new.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(GestionnaireMailer).not_to have_received(:last_week_overview) }
|
|
|
|
end
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
|
2017-05-19 16:21:11 +02:00
|
|
|
context 'if the feature is disabled' do
|
|
|
|
before { allow(Features).to receive(:weekly_overview).and_return(false) }
|
2017-05-12 17:41:03 +02:00
|
|
|
before :each do
|
2017-05-19 16:21:11 +02:00
|
|
|
allow(Gestionnaire).to receive(:all)
|
2017-05-12 17:41:03 +02:00
|
|
|
WeeklyOverviewWorker.new.perform
|
|
|
|
end
|
|
|
|
|
2017-05-19 16:21:11 +02:00
|
|
|
it { expect(Gestionnaire).not_to receive(:all) }
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|