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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Merge remote-tracking branch 'origin/dev' into fix/stable_webhook_events
Oliver Günthercf52c2cddfef
diff --cc app/models/journal_notification_mailer.rbindex 00000000000,08ceee69e3a..e69de29bb2dmode 000000,100644..100644--- a/app/models/journal_notification_mailer.rb+++ b/app/models/journal_notification_mailer.rbdiff --cc app/services/notifications/journal_notification_service.rbindex c2a4bc1e092,00000000000..679082dbd1emode 100644,000000..100644--- a/app/services/notifications/journal_notification_service.rb+++ b/app/services/notifications/journal_notification_service.rb@@@ -1,69 -1,0 +1,68 @@@+#-- encoding: UTF-8++#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++class Notifications::JournalNotificationService+ class << self+ include Notifications::JournalNotifier++ def call(journal, send_mails)+ if journal.journable_type == 'WorkPackage'+ handle_work_package_journal(journal, send_mails)+ end+ end++ private++ def handle_work_package_journal(journal, send_mails)+ notify_for_wp_predecessor(journal, send_mails)+ enqueue_work_package_notification(journal, send_mails)+ end++ # Send the notification on behalf of the predecessor in case it could not send it on its own+ def notify_for_wp_predecessor(journal, send_mails)+ aggregated = find_aggregated_journal_for(journal)++ if Journal::AggregatedJournal.hides_notifications?(aggregated, aggregated.predecessor)+ aggregated_predecessor = find_aggregated_journal_for(aggregated.predecessor)+ notify_journal_complete(aggregated_predecessor, send_mails)+ end+ end++ def enqueue_work_package_notification(journal, send_mails)- job = EnqueueWorkPackageNotificationJob.new(journal.id, send_mails)- Delayed::Job.enqueue job,- run_at: delivery_time,- priority: ::ApplicationJob.priority_number(:notification)++ EnqueueWorkPackageNotificationJob++ .set(wait_until: delivery_time)++ .perform_later(journal.id, send_mails)+ end++ def delivery_time+ Setting.journal_aggregation_time_minutes.to_i.minutes.from_now+ end+ end+enddiff --cc app/services/notifications/journal_wp_mail_service.rbindex 0561f869bb3,00000000000..3a912436169mode 100644,000000..100644--- a/app/services/notifications/journal_wp_mail_service.rb+++ b/app/services/notifications/journal_wp_mail_service.rb@@@ -1,137 -1,0 +1,133 @@@+#-- encoding: UTF-8++#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++class Notifications::JournalWPMailService+ class << self+ include Notifications::JournalNotifier++ def call(journal, send_mails)+ journal_complete_mail(journal, send_mails)+ end++ private++ def journal_complete_mail(journal, send_mails)+ return nil unless send_mail?(journal, send_mails)++ author = User.find_by(id: journal.user_id) || DeletedUser.first++ notification_receivers(journal.journable, journal).each do |recipient|- job = DeliverWorkPackageNotificationJob.new(journal.id,- recipient.id,- author.id)- Delayed::Job.enqueue job,- priority: ::ApplicationJob.priority_number(:notification)++ DeliverWorkPackageNotificationJob.perform_later(journal.id, recipient.id, author.id)+ end+ end++ def notification_receivers(work_package, journal)+ (work_package.recipients + work_package.watcher_recipients + mentioned(work_package, journal)).uniq+ end++ def mentioned(work_package, journal)+ mentioned_ids(journal)+ .where(id: User.allowed(:view_work_packages, work_package.project))+ .where.not(mail_notification: User::USER_MAIL_OPTION_NON.first)+ end++ def text_for_mentions(journal)+ potential_text = ""+ potential_text << journal.notes if journal.try(:notes)++ %i[description subject].each do |field|+ details = journal.details[field]++ if details.present?+ potential_text << "\n" + Redmine::Helpers::Diff.new(*details).additions.join(' ')+ end+ end+ potential_text+ end++ def mentioned_ids(journal)+ text = text_for_mentions(journal)+ user_ids, user_login_names, group_ids = text+ .scan(/\b(?:user#([\d]+))|(?:user:"(.+?)")|(?:group#([\d]+))\b/)+ .transpose+ .each(&:compact!)++ base_scope = User+ .includes(:groups)+ .references(:groups_users)++ by_id = base_scope.where(id: user_ids || [])+ by_login = base_scope.where(login: user_login_names || [])+ by_group = base_scope.where(groups_users: { id: group_ids || [] })++ by_id+ .or(by_login)+ .or(by_group)+ end++ def send_mail?(journal, send_mails)+ send_mails && ::UserMailer.perform_deliveries && send_mail_setting?(journal)+ end++ def send_mail_setting?(journal)+ notify_for_wp_added?(journal) ||+ notify_for_wp_updated?(journal) ||+ notify_for_notes?(journal) ||+ notify_for_status?(journal) ||+ notify_for_priority(journal)+ end++ def notify_for_wp_added?(journal)+ notification_enabled?('work_package_added') && journal.initial?+ end++ def notify_for_wp_updated?(journal)+ notification_enabled?('work_package_updated') && !journal.initial?+ end++ def notify_for_notes?(journal)+ notification_enabled?('work_package_note_added') && journal.notes.present?+ end++ def notify_for_status?(journal)+ notification_enabled?('status_updated') &&+ journal.details.has_key?(:status_id)+ end++ def notify_for_priority(journal)+ notification_enabled?('work_package_priority_updated') &&+ journal.details.has_key?(:priority_id)+ end++ def notification_enabled?(name)+ Setting.notified_events.include?(name)+ end+ end+enddiff --cc app/workers/enqueue_work_package_notification_job.rbindex 52f664196a3,d527d2b2fb8..028ffdf827b--- a/app/workers/enqueue_work_package_notification_job.rb+++ b/app/workers/enqueue_work_package_notification_job.rb@@@ -29,19 -29,17 +29,20 @@@# Enqueuesclass EnqueueWorkPackageNotificationJob < ApplicationJob++ queue_with_priority :notification+- def perform(journal_id, author_id)+ include Notifications::JournalNotifier+- def initialize(journal_id, send_mails)++ def perform(journal_id, send_mails)+ # This is caused by a DJ job running as ActiveJob@journal_id = journal_id- @author_id = author_id+ @send_mails = send_mails- end- def perform# if the WP has been deleted the unaggregated journal will have been deleted too# and our job here is done- return nil unless raw_journal+ return unless raw_journal- @journal = find_aggregated_journal+ journal = find_aggregated_journal_for(raw_journal)# If we can't find the aggregated journal, it was superseded by a journal that aggregated ours.# In that case a job for the new journal will have been enqueued that is now responsible fordiff --cc modules/webhooks/lib/open_project/webhooks/event_resources/work_package.rbindex 02f54ba212f,3547733cd70..d250675987b--- a/modules/webhooks/lib/open_project/webhooks/event_resources/work_package.rb+++ b/modules/webhooks/lib/open_project/webhooks/event_resources/work_package.rb@@@ -20,10 -20,10 +20,10 @@@ module OpenProject::Webhooks::EventResoprotecteddef handle_notification(payload, event_name)- action = payload[:initial] ? "created" : "updated"+ action = payload[:journal].initial? ? "created" : "updated"event_name = prefixed_event_name(action)active_webhooks.with_event_name(event_name).pluck(:id).each do |id|- Delayed::Job.enqueue WorkPackageWebhookJob.new(id, payload[:journal].id, event_name)- WorkPackageWebhookJob.perform_later(id, payload[:journal_id], event_name)++ WorkPackageWebhookJob.perform_later(id, payload[:journal].id, event_name)endendenddiff --cc spec/requests/api/v3/work_package_resource_spec.rbindex c08d593884a,ac04e767b21..2532f6a5db0--- a/spec/requests/api/v3/work_package_resource_spec.rb+++ b/spec/requests/api/v3/work_package_resource_spec.rb@@@ -1040,22 -1050,24 +1050,25 @@@ describe 'API v3 Work package resource'status.save!priority.save!- FactoryBot.create(:user_preference, user: current_user, others: { no_self_notified: false })+ FactoryBot.create(:user_preference, user: current_user, others: {no_self_notified: false})post path, parameters.to_json, 'CONTENT_TYPE' => 'application/json'++ perform_enqueued_jobsendcontext 'notifications' dolet(:permissions) { %i[add_work_packages view_project view_work_packages] }it 'sends a mail by default' do- expect(ActionMailer::Base.deliveries.count).to eq(1)- expect(EnqueueWorkPackageNotificationJob)++ expect(DeliverWorkPackageNotificationJob)+ .to have_been_enqueued+ .at_least(1)endcontext 'without notifications' dolet(:path) { "#{api_v3_paths.work_packages}?notify=false" }it 'should not send a mail' do- expect(ActionMailer::Base.deliveries.count).to eq(0)- expect(EnqueueWorkPackageNotificationJob).not_to have_been_enqueued++ expect(DeliverWorkPackageNotificationJob).not_to have_been_enqueuedendend@@@ -1063,7 -1075,9 +1076,9 @@@let(:path) { "#{api_v3_paths.work_packages}?notify=true" }it 'should send a mail' do- expect(ActionMailer::Base.deliveries.count).to eq(1)- expect(EnqueueWorkPackageNotificationJob)++ expect(DeliverWorkPackageNotificationJob)+ .to have_been_enqueued+ .at_least(1)endendenddiff --cc spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rbindex f881e267f09,e7137d89390..ebdaf383532--- a/spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rb@@@ -295,20 -295,20 +295,21 @@@ describe API::V3::WorkPackages::WorkPacFactoryBot.create(:user_preference, user: current_user, others: { no_self_notified: false })post path, parameters.to_json, 'CONTENT_TYPE' => 'application/json'++ perform_enqueued_jobsendcontext 'notifications' dolet(:permissions) { [:add_work_packages, :view_project, :view_work_packages] }it 'sends a mail by default' do- expect(ActionMailer::Base.deliveries.count).to eq(1)- expect(EnqueueWorkPackageNotificationJob).to have_been_enqueued++ expect(DeliverWorkPackageNotificationJob).to have_been_enqueuedendcontext 'without notifications' dolet(:path) { "#{api_v3_paths.work_packages_by_project(project.id)}?notify=false" }it 'should not send a mail' do- expect(ActionMailer::Base.deliveries.count).to eq(0)- expect(EnqueueWorkPackageNotificationJob).not_to have_been_enqueued++ expect(DeliverWorkPackageNotificationJob).not_to have_been_enqueuedendend@@@ -316,7 -316,7 +317,7 @@@let(:path) { "#{api_v3_paths.work_packages_by_project(project.id)}?notify=true" }it 'should send a mail' do- expect(ActionMailer::Base.deliveries.count).to eq(1)- expect(EnqueueWorkPackageNotificationJob).to have_been_enqueued++ expect(DeliverWorkPackageNotificationJob).to have_been_enqueuedendendenddiff --cc spec/services/notifications/journal_notification_service_spec.rbindex 436c8b8407c,db9e724eb8a..0a170008ed7--- a/spec/services/notifications/journal_notification_service_spec.rb+++ b/spec/services/notifications/journal_notification_service_spec.rb@@@ -77,15 -66,34 +66,15 @@@ describe Notifications::JournalNotificaendend- shared_examples_for 'handles deliveries' do |notification_setting|- context 'setting enabled' do- let(:notifications) { [notification_setting] }-- it_behaves_like 'enqueues a regular notification'-- context 'insufficient work package changes' do- let(:journal) { another_work_package.journals.last }- let(:another_work_package) {- FactoryBot.create(:work_package,- project: project,- author: user,- type: project.types.first)- }- before do- another_work_package.add_journal(user)- another_work_package.description = 'needs more changes'- another_work_package.save!(validate: false)- end+ shared_examples_for 'sends notification' do+ it 'sends a notification' do+ expect(OpenProject::Notifications)+ .to receive(:send)- .with(OpenProject::Events::AGGREGATED_WORK_PACKAGE_JOURNAL_READY,- journal: an_instance_of(Journal::AggregatedJournal),- send_mail: send_mails)++ .with(OpenProject::Events::AGGREGATED_WORK_PACKAGE_JOURNAL_READY,++ journal: an_instance_of(Journal::AggregatedJournal),++ send_mail: send_mails)- it 'sends no notification' do- expect { call_listener }.not_to enqueue_job(EnqueueWorkPackageNotificationJob)- end- end- end-- it 'sends no notification' do- expect { call_listener }.not_to enqueue_job(EnqueueWorkPackageNotificationJob)+ call_listenerendenddiff --cc spec/services/notifications/journal_wp_mail_service_spec.rbindex 314c37831f3,00000000000..b90364c906bmode 100644,000000..100644--- a/spec/services/notifications/journal_wp_mail_service_spec.rb+++ b/spec/services/notifications/journal_wp_mail_service_spec.rb@@@ -1,359 -1,0 +1,347 @@@+#-- encoding: UTF-8++#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#+++require 'spec_helper'++describe Notifications::JournalWPMailService do+ let(:project) { FactoryBot.create(:project_with_types) }+ let(:role) { FactoryBot.create(:role, permissions: [:view_work_packages]) }+ let(:author) do+ FactoryBot.build(:user,+ mail_notification: 'none',+ member_in_project: project,+ member_through_role: role)+ end+ let(:recipient) do+ FactoryBot.create(:user,+ member_in_project: project,+ member_through_role: role,+ login: "johndoe")+ end+ let(:work_package) do+ FactoryBot.create(:work_package,+ project: project,+ author: author,+ assigned_to: recipient,+ type: project.types.first)+ end+ let(:journal) { journal_1 }+ let(:journal_1) { work_package.journals.first }+ let(:journal_2_with_notes) do+ work_package.add_journal author, 'something I have to say'+ work_package.save(validate: false)+ work_package.journals.last+ end+ let(:journal_2_with_status) do+ work_package.status = FactoryBot.create(:status)+ work_package.save(validate: false)+ work_package.journals.last+ end+ let(:journal_2_with_priority) do+ work_package.priority = FactoryBot.create(:priority)+ work_package.save(validate: false)+ work_package.journals.last+ end+ let(:send_mails) { true }+ let(:notification_setting) { %w(work_package_added work_package_updated work_package_note_added status_updated work_package_priority_updated) }++ def call+ described_class.call(journal, send_mails)+ end++ before do+ # make sure no other calls are made due to WP creation/update+ allow(OpenProject::Notifications).to receive(:send) # ... and do nothing++ login_as(author)+ allow(Setting).to receive(:notified_events).and_return(notification_setting)-- allow(Delayed::Job).to receive(:enqueue)+ end++ shared_examples_for 'sends mail' do+ let(:sender) { author }++ it 'sends a mail' do- deliver_job = double('deliver job')-- expect(DeliverWorkPackageNotificationJob)- .to receive(:new)++ expect { call }++ .to enqueue_job(DeliverWorkPackageNotificationJob)+ .with(journal.id, recipient.id, sender.id)- .and_return(deliver_job)-- expect(Delayed::Job)- .to receive(:enqueue)- .with(deliver_job, priority: anything)-- call+ end+ end++ shared_examples_for 'sends no mail' do+ it 'sends no mail' do- expect(Delayed::Job).not_to receive(:enqueue)-++ expect { call }.to_not enqueue_job(DeliverWorkPackageNotificationJob)+ call+ end+ end++ it_behaves_like 'sends mail'++ context 'notification for work_package_added disabled' do+ let(:notification_setting) { %w(work_package_updated work_package_note_added) }++ it_behaves_like 'sends no mail'+ end++ context 'if the journal has a note' do+ let(:journal) { journal_2_with_notes }++ context 'notification for work_package_updated and work_package_note_added disabled' do+ let(:notification_setting) { %w(work_package_added status_updated work_package_priority_updated) }++ it_behaves_like 'sends no mail'+ end++ context 'notification for work_package_updated enabled' do+ let(:notification_setting) { %w(work_package_updated) }++ it_behaves_like 'sends mail'+ end++ context 'notification for work_package_note_added enabled' do+ let(:notification_setting) { %w(work_package_note_added) }++ it_behaves_like 'sends mail'+ end+ end++ context 'if the journal has status update' do+ let(:journal) { journal_2_with_status }++ context 'notification for work_package_updated and status_updated disabled' do+ let(:notification_setting) { %w(work_package_added work_package_note_added work_package_priority_updated) }++ it_behaves_like 'sends no mail'+ end++ context 'notification for work_package_updated enabled' do+ let(:notification_setting) { %w(work_package_updated) }++ it_behaves_like 'sends mail'+ end++ context 'notification for status_updated enabled' do+ let(:notification_setting) { %w(status_updated) }++ it_behaves_like 'sends mail'+ end+ end++ context 'if the journal has priority' do+ let(:journal) { journal_2_with_priority }++ context 'notification for work_package_updated and work_package_priority_updated disabled' do+ let(:notification_setting) { %w(work_package_added work_package_note_added status_updated) }++ it_behaves_like 'sends no mail'+ end++ context 'notification for work_package_updated enabled' do+ let(:notification_setting) { %w(work_package_updated) }++ it_behaves_like 'sends mail'+ end++ context 'notification for work_package_priority_updated enabled' do+ let(:notification_setting) { %w(work_package_priority_updated) }++ it_behaves_like 'sends mail'+ end+ end++ context 'if the author has been deleted' do+ let!(:deleted_user) { DeletedUser.first }++ before do+ work_package+ author.destroy+ end++ it_behaves_like 'sends mail' do+ let(:sender) { deleted_user }+ end+ end++ context 'user is mentioned' do+ let(:work_package) do+ FactoryBot.create(:work_package,+ project: project,+ author: author,+ type: project.types.first)+ end++ shared_examples_for 'mentioned' do+ context 'for users' do+ context "mentioned is allowed to view the work package" do+ context "The added text contains a login name" do+ let(:note) { "Hello user:\"#{recipient.login}\"" }++ context "that is pretty normal word" do+ it_behaves_like 'sends mail'+ end++ context "that is an email address" do+ let(:recipient) do+ FactoryBot.create(:user,+ member_in_project: project,+ member_through_role: role,+ login: "[email protected]")+ end++ it_behaves_like 'sends mail'+ end+ end++ context "The added text contains a user ID" do+ let(:note) { "Hello user##{recipient.id}" }++ it_behaves_like 'sends mail'+ end++ context "the recipient turned off all mail notifications" do+ let(:recipient) do+ FactoryBot.create(:user,+ member_in_project: project,+ member_through_role: role,+ mail_notification: 'none')+ end++ let(:note) do+ "Hello user:\"#{recipient.login}\", hey user##{recipient.id}"+ end++ it_behaves_like 'sends no mail'+ end+ end++ context "mentioned user is not allowed to view the work package" do+ let(:recipient) do+ FactoryBot.create(:user,+ login: "[email protected]")+ end+ let(:note) do+ "Hello user:#{recipient.login}, hey user##{recipient.id}"+ end++ it_behaves_like 'sends no mail'+ end+ end++ context 'for groups' do+ let(:recipient) { FactoryBot.create(:user) }++ let(:group) do+ FactoryBot.create(:group) do |group|+ group.users << recipient++ FactoryBot.create(:member,+ project: project,+ principal: group,+ roles: [role])+ end+ end++ let(:note) do+ "Hello group##{group.id}"+ end++ context 'group member is allowed to view the work package' do+ context 'user wants to receive notifications' do+ it_behaves_like 'sends mail'+ end++ context 'user disabled notifications' do+ let(:recipient) { FactoryBot.create(:user, mail_notification: User::USER_MAIL_OPTION_NON.first) }++ it_behaves_like 'sends no mail'+ end+ end++ context 'group is not allowed to view the work package' do+ let(:role) { FactoryBot.create(:role, permissions: []) }++ it_behaves_like 'sends no mail'++ context 'but group member is allowed individually' do+ let(:recipient) do+ FactoryBot.create(:user,+ member_in_project: project,+ member_with_permissions: [:view_work_packages])+ end++ it_behaves_like 'sends mail'+ end+ end+ end+ end++ context 'in the journal notes' do+ let(:journal) { journal_2_with_notes }+ let(:journal_2_with_notes) do+ work_package.add_journal author, note+ work_package.save(validate: false)+ work_package.journals.last+ end++ it_behaves_like 'mentioned'+ end++ context 'in the description' do+ let(:journal) { journal_2_with_description }+ let(:journal_2_with_description) do+ work_package.description = note+ work_package.save(validate: false)+ work_package.journals.last+ end++ it_behaves_like 'mentioned'+ end++ context 'in the subject' do+ let(:journal) { journal_2_with_subject }+ let(:journal_2_with_subject) do+ work_package.subject = note+ work_package.save(validate: false)+ work_package.journals.last+ end++ it_behaves_like 'mentioned'+ end+ end+end++describe 'initialization' do+ it 'subscribes the listener' do+ expect(Notifications::JournalWPMailService).to receive(:call)++ OpenProject::Notifications.send(+ OpenProject::Events::AGGREGATED_WORK_PACKAGE_JOURNAL_READY,+ journal: double('journal', initial?: true)+ )+ end+enddiff --cc spec/workers/mail_notification_jobs/enqueue_work_package_notification_job_spec.rbindex e4fb90b4de7,e2aede1dbd5..0e0931ce669--- a/spec/workers/mail_notification_jobs/enqueue_work_package_notification_job_spec.rb+++ b/spec/workers/mail_notification_jobs/enqueue_work_package_notification_job_spec.rb@@@ -43,39 -42,28 +43,40 @@@ describe EnqueueWorkPackageNotificationauthor: author,assigned_to: recipient)end- let(:journal) { work_package.journals.first }- let(:instance) { described_class.new }- subject { instance.perform(journal.id, author.id) }+ let(:journal) { journal_1 }+ let(:journal_1) { work_package.journals.first }+ let(:journal_2) do+ work_package.add_journal author, 'something I have to say'+ work_package.save(validate: false)+ work_package.journals.last+ end+ let(:send_mail) { true }- subject { described_class.new(journal.id, send_mail) }++++ subject { described_class.new.perform(journal.id, send_mail) }before do# make sure no other calls are made due to WP creation/updateallow(OpenProject::Notifications).to receive(:send) # ... and do nothingend- it 'sends a mail' do- expect(DeliverNotificationJob).to receive(:perform_later)- subject- end+ shared_examples_for 'sends notification' do+ it 'sends a notification' do+ expect(OpenProject::Notifications)+ .to receive(:send)+ .with(OpenProject::Events::AGGREGATED_WORK_PACKAGE_JOURNAL_READY,+ journal: an_instance_of(Journal::AggregatedJournal),+ send_mail: send_mail)- subject.perform- context 'non-existant journal' do- before do- journal.destroy++ subjectend+ end++ shared_examples_for 'sends no notification' do+ it 'sends no notification' do+ expect(OpenProject::Notifications)+ .not_to receive(:send)- subject.perform- it 'sends no mail' do- expect(DeliverNotificationJob).not_to receive(:perform_later)+ subjectendend