From 63d961231587b2b5951785f564dcf35cf75c6cbf Mon Sep 17 00:00:00 2001 From: Just Me Date: Sat, 31 Aug 2024 21:17:15 +0300 Subject: [PATCH] Use test job queue adapter and perform mail jobs explicitly --- config/environments/test.rb | 2 + spec/features/registration_spec.rb | 90 +++++++++++++++++++++++++----- spec/rails_helper.rb | 1 + 3 files changed, 78 insertions(+), 15 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index ca9aefec..b8374fa6 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -61,4 +61,6 @@ # Raise error when a before_action's only/except options reference missing actions. # config.action_controller.raise_on_missing_callback_actions = true + + config.active_job.queue_adapter = :test end diff --git a/spec/features/registration_spec.rb b/spec/features/registration_spec.rb index 5c073625..26557c86 100644 --- a/spec/features/registration_spec.rb +++ b/spec/features/registration_spec.rb @@ -20,7 +20,11 @@ before { click_button 'commit' } it { expect(page).to have_content 'Ви успішно зареєстровані.' } - it('delivers email') { expect(ActionMailer::Base.deliveries).to include(registration_email) } + + it 'delivers email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to include(registration_email) + end end context 'with duplicated name' do @@ -32,7 +36,11 @@ end it { expect(page).to have_content "Учасник на ім'я #{params[:name]} вже зареєстрований" } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end context 'with invalid registration secret' do @@ -41,7 +49,11 @@ before { click_button 'commit' } it { expect(page).to have_content 'Код доступу помилковий' } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end context 'without contest site' do @@ -50,7 +62,11 @@ before { click_button 'commit' } it { expect(page).to have_content 'Заклад, у якому ви пишете олімпіаду не може бути порожнім' } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end context 'without grade' do @@ -59,7 +75,11 @@ before { click_button 'commit' } it { expect(page).to have_content 'Клас не може бути порожнім' } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end context 'without city' do @@ -68,7 +88,11 @@ before { click_button 'commit' } it { expect(page).to have_content 'Місто не може бути порожнім' } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end context 'without email' do @@ -78,7 +102,11 @@ it('stays on registration page') { expect(page).to have_current_path(registration_path) } it { expect(page).to_not have_content 'Ваш e-mail не може бути порожнім' } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end context 'without institution' do @@ -87,7 +115,11 @@ before { click_button 'commit' } it { expect(page).to have_content 'Ваш навчальний заклад не може бути порожнім' } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end context 'without name' do @@ -97,7 +129,11 @@ it('stays on registration page') { expect(page).to have_current_path(registration_path) } it { expect(page).to_not have_content 'Прізвище, Ім\'я, По батькові не може бути пустим' } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end end @@ -115,7 +151,11 @@ before { click_button 'commit' } it { expect(page).to have_content 'Ви успішно зареєстровані.' } - it('delivers email') { expect(ActionMailer::Base.deliveries).to include(registration_email) } + + it 'delivers email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to include(registration_email) + end end context 'without contest_site' do @@ -125,7 +165,11 @@ it('stays on registration page') { expect(page).to have_current_path(registration_path) } it { expect(page).to_not have_content 'Заклад, у якому ви пишете олімпіаду не може бути порожнім' } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end end @@ -143,7 +187,11 @@ before { click_button 'commit' } it { expect(page).to have_content 'Ви успішно зареєстровані.' } - it('delivers email') { expect(ActionMailer::Base.deliveries).to include(registration_email) } + + it 'delivers email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to include(registration_email) + end end context 'without institution' do @@ -153,7 +201,11 @@ it('stays on registration page') { expect(page).to have_current_path(registration_path) } it { expect(page).to_not have_content 'Ваш навчальний заклад не може бути порожнім' } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end end @@ -171,7 +223,11 @@ before { click_button 'commit' } it { expect(page).to have_content 'Ви успішно зареєстровані.' } - it('delivers email') { expect(ActionMailer::Base.deliveries).to include(registration_email) } + + it 'delivers email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to include(registration_email) + end end context 'without city' do @@ -181,7 +237,11 @@ it('stays on registration page') { expect(page).to have_current_path(registration_path) } it { expect(page).to_not have_content 'Місто не може бути порожнім' } - it('does not deliver email') { expect(ActionMailer::Base.deliveries).to_not include(registration_email) } + + it 'does not deliver email' do + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries).to_not include(registration_email) + end end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4ef819bc..88492a1f 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -108,6 +108,7 @@ # config.filter_gems_from_backtrace("gem name") config.include FactoryBot::Syntax::Methods config.include FormHelpers + config.include ActiveJob::TestHelper end browser = ENV.fetch('UI_TEST_ENGINE', :firefox).to_sym