Commit 3d9b36b8 authored by David Kim's avatar David Kim

Merge branch 'fix-sidekiq-mailer-specs' into 'master'

Fix Sidekiq mailer specs

See merge request gitlab-org/gitlab!64295
parents 9446a9bf 7d7472fd
......@@ -2,22 +2,8 @@
require 'spec_helper'
RSpec.describe 'Mailer retries' do
# We need to ensure that this runs through Sidekiq to take
# advantage of the middleware. There is a Rails bug that means we
# have to do some extra steps to make this happen:
# https://github.com/rails/rails/issues/37270#issuecomment-553927324
around do |example|
descendants = ActiveJob::Base.descendants + [ActiveJob::Base]
descendants.each(&:disable_test_adapter)
ActiveJob::Base.queue_adapter = :sidekiq
example.run
descendants.each { |a| a.queue_adapter = :test }
end
it 'sets retries for mailers to 3', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332645' do
RSpec.describe 'Mailer retries', :sidekiq_mailers do
it 'sets retries for mailers to 3' do
DeviseMailer.user_admin_approval(create(:user)).deliver_later
expect(Sidekiq::Queues['mailers'].first).to include('retry' => 3)
......
......@@ -89,21 +89,7 @@ RSpec.describe 'Marginalia spec' do
end
end
describe 'for ActionMailer delivery jobs' do
# We need to ensure that this runs through Sidekiq to take
# advantage of the middleware. There is a Rails bug that means we
# have to do some extra steps to make this happen:
# https://github.com/rails/rails/issues/37270#issuecomment-553927324
around do |example|
descendants = ActiveJob::Base.descendants + [ActiveJob::Base]
descendants.each(&:disable_test_adapter)
ActiveJob::Base.queue_adapter = :sidekiq
example.run
descendants.each { |a| a.queue_adapter = :test }
end
describe 'for ActionMailer delivery jobs', :sidekiq_mailers do
let(:delivery_job) { MarginaliaTestMailer.first_user.deliver_later }
let(:recorded) do
......
......@@ -929,6 +929,10 @@ RSpec.describe NotificationService, :mailer do
end
context 'design management is disabled' do
before do
enable_design_management(false)
end
it 'does not notify anyone' do
notification.new_note(note)
......
......@@ -20,4 +20,25 @@ RSpec.configure do |config|
config.around(:example, :sidekiq_inline) do |example|
gitlab_sidekiq_inline { example.run }
end
# Some specs need to run mailers through Sidekiq explicitly, rather
# than the ActiveJob test adapter. There is a Rails bug that means we
# have to do some extra steps to make this happen:
# https://github.com/rails/rails/issues/37270
#
# In particular, we can't use an `around` hook because then the 'before' part
# of that will run before the `before_setup` hook in ActiveJob::TestHelper,
# which doesn't do what we want.
#
config.before(:example, :sidekiq_mailers) do
queue_adapter_changed_jobs.each { |k| k.queue_adapter = :sidekiq }
queue_adapter_changed_jobs.each(&:disable_test_adapter)
end
config.after(:example, :sidekiq_mailers) do
queue_adapter_changed_jobs.each do |klass|
klass.queue_adapter = :test
klass.enable_test_adapter(ActiveJob::QueueAdapters::TestAdapter.new)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment