Skip to content

Commit

Permalink
Use test job queue adapter and perform mail jobs explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
just806me committed Aug 31, 2024
1 parent 0c2dc57 commit 63d9612
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 15 deletions.
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
90 changes: 75 additions & 15 deletions spec/features/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63d9612

Please sign in to comment.