demarches-normaliennes/spec/jobs/cron/weekly_overview_job_spec.rb

49 lines
1.5 KiB
Ruby
Raw Normal View History

RSpec.describe Cron::WeeklyOverviewJob, type: :job do
describe 'perform' do
let!(:instructeur) { create(:instructeur) }
let(:overview) { double('overview') }
context 'if the feature is enabled' do
2018-04-18 12:24:37 +02:00
before do
Rails.application.config.ds_weekly_overview = true
end
after do
Rails.application.config.ds_weekly_overview = false
2018-04-18 12:24:37 +02:00
end
subject(:run_job) { Cron::WeeklyOverviewJob.new.perform }
# See also spec/mailers/instructeur_mailer_spec.rb
context 'with one instructeur with one overview' do
let(:mailer_double) { double('mailer', deliver_later: true) }
2018-04-18 12:24:37 +02:00
before do
allow(InstructeurMailer).to receive(:last_week_overview).and_return(mailer_double)
run_job
end
it { expect(InstructeurMailer).to have_received(:last_week_overview).with(instructeur) }
it { expect(mailer_double).to have_received(:deliver_later) }
end
context 'with one instructeur with no overviews' do
2018-04-18 12:24:37 +02:00
before do
allow(InstructeurMailer).to receive(:last_week_overview).and_return(nil)
run_job
end
it { expect(InstructeurMailer).to have_received(:last_week_overview).with(instructeur) }
it { expect { run_job }.not_to raise_error(NoMethodError) }
end
end
context 'if the feature is disabled' do
2018-04-18 12:24:37 +02:00
before do
allow(Instructeur).to receive(:find_each)
Cron::WeeklyOverviewJob.new.perform
end
it { expect(Instructeur).not_to receive(:find_each) }
end
end
end