Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

ensure all enqueued jobs are run

ulferts5e33c4b637f9
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index 6c3e262fe05..b831170a55e 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -188,7 +188,9 @@ describe UsersController, type: :controller do
expect(ActionMailer::Base.deliveries).to be_empty
as_logged_in_user admin do
- post :resend_invitation, params: { id: invited_user.id }
+ perform_enqueued_jobs do
+ post :resend_invitation, params: { id: invited_user.id }
+ end
end
end
@@ -197,7 +199,6 @@ describe UsersController, type: :controller do
end
it 'sends another activation email' do
- perform_enqueued_jobs
mail = ActionMailer::Base.deliveries.first.body.parts.first.body.to_s
token = Token::Invitation.find_by user_id: invited_user.id
diff --git a/spec/features/users/create_spec.rb b/spec/features/users/create_spec.rb
index 846ba5e3218..dbd610ee6b3 100644
--- a/spec/features/users/create_spec.rb
+++ b/spec/features/users/create_spec.rb
@@ -35,12 +35,11 @@ describe 'create users', type: :feature, selenium: true do
let(:new_user_page) { Pages::NewUser.new }
before do
- allow(User).to receive(:current).and_return current_user
+ login_as current_user
end
shared_examples_for 'successful user creation' do
let(:mail) do
- perform_enqueued_jobs
ActionMailer::Base.deliveries.last
end
let(:mail_body) { mail.body.parts.first.body.to_s }
@@ -68,7 +67,9 @@ describe 'create users', type: :feature, selenium: true do
last_name: 'boblast',
- new_user_page.submit!
+ perform_enqueued_jobs do
+ new_user_page.submit!
+ end
end
it_behaves_like 'successful user creation' do
@@ -109,7 +110,9 @@ describe 'create users', type: :feature, selenium: true do
auth_source: auth_source.name
- new_user_page.submit!
+ perform_enqueued_jobs do
+ new_user_page.submit!
+ end
end
after do
diff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rb
index 3c1b63d1f5c..937750c7147 100644
--- a/spec/models/mail_handler_spec.rb
+++ b/spec/models/mail_handler_spec.rb
@@ -231,10 +231,11 @@ describe MailHandler, type: :model do
end
it 'sends a mail as a work package has been created' do
- subject
+ perform_enqueued_jobs do
+ subject
+ end
# Email notification should be sent
- perform_enqueued_jobs
mail = ActionMailer::Base.deliveries.last
expect(mail)
diff --git a/spec/models/wiki_content_spec.rb b/spec/models/wiki_content_spec.rb
index 8eb06959cba..d1a1e72e21a 100644
--- a/spec/models/wiki_content_spec.rb
+++ b/spec/models/wiki_content_spec.rb
@@ -71,8 +71,9 @@ describe WikiContent, type: :model do
project_watcher
expect {
- content.save!
- perform_enqueued_jobs
+ perform_enqueued_jobs do
+ content.save!
+ end
}
.to change { ActionMailer::Base.deliveries.size }
.by(2)
@@ -86,14 +87,12 @@ describe WikiContent, type: :model do
wiki_watcher
project_watcher
- content
- perform_enqueued_jobs
-
content.text = 'My new content'
expect {
- content.save!
- perform_enqueued_jobs
+ perform_enqueued_jobs do
+ content.save!
+ end
}
.to change { ActionMailer::Base.deliveries.size }
.by(3)
diff --git a/spec/models/work_package/work_package_action_mailer_spec.rb b/spec/models/work_package/work_package_action_mailer_spec.rb
index b909405d6cb..af6fd0853f1 100644
--- a/spec/models/work_package/work_package_action_mailer_spec.rb
+++ b/spec/models/work_package/work_package_action_mailer_spec.rb
@@ -48,14 +48,15 @@ describe WorkPackage, type: :model do
allow(work_package).to receive(:watcher_recipients).and_return([user_2])
Journal::NotificationConfiguration.with true do
- work_package.save
+ perform_enqueued_jobs do
+ work_package.save
+ end
end
end
subject { ActionMailer::Base.deliveries.size }
it do
- perform_enqueued_jobs
expect(subject).to eq 2
end
diff --git a/spec/models/work_package/work_package_notifications_spec.rb b/spec/models/work_package/work_package_notifications_spec.rb
index 919955393fb..082e74a8013 100644
--- a/spec/models/work_package/work_package_notifications_spec.rb
+++ b/spec/models/work_package/work_package_notifications_spec.rb
@@ -37,7 +37,7 @@ describe WorkPackage, type: :model do
let(:user) { admin }
let(:current_user) { FactoryBot.create :admin }
let(:project) { FactoryBot.create :project }
- let!(:work_package) do
+ let(:work_package) do
FactoryBot.create :work_package,
author: user,
subject: 'I can see you',
@@ -46,7 +46,10 @@ describe WorkPackage, type: :model do
context 'after creation' do
it "are sent to the work package's author" do
- perform_enqueued_jobs
+ perform_enqueued_jobs do
+ work_package
+ end
+
mail = ActionMailer::Base.deliveries.detect { |m| m.subject.include? 'I can see you' }
expect(mail).to be_present
@@ -65,6 +68,10 @@ describe WorkPackage, type: :model do
end
it "are not sent to the work package's author" do
+ perform_enqueued_jobs do
+ work_package
+ end
+
mail = ActionMailer::Base.deliveries.detect { |m| m.subject.include? 'I can see you' }
expect(mail).not_to be_present
@@ -74,11 +81,12 @@ describe WorkPackage, type: :model do
describe 'after update' do
before do
- work_package.update subject: 'the wind of change'
+ perform_enqueued_jobs do
+ work_package.update subject: 'the wind of change'
+ end
end
it "are sent to the work package's author" do
- perform_enqueued_jobs
mail = ActionMailer::Base.deliveries.detect { |m| m.subject.include? 'the wind of change' }
expect(mail).to be_present
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index cdc56ee527a..8042f25f8f0 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -73,6 +73,9 @@ RSpec.configure do |config|
config.include JsonSpec::Helpers
# Add job helper
+ # Only the ActiveJob::TestHelper is actually used but it in turn requires
+ # e.g. assert_nothing_raised
+ config.include ::ActiveSupport::Testing::Assertions
config.include ::ActiveJob::TestHelper
OpenProject::Configuration['attachments_storage_path'] = 'tmp/files'