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

update spec expectation which used to be incorrect

ulferts5da326043d32
diff --git a/spec/services/notifications/mail_service_mentioned_integration_spec.rb b/spec/services/notifications/mail_service_mentioned_integration_spec.rb
index 22f04575a87..0cba2953ca5 100644
--- a/spec/services/notifications/mail_service_mentioned_integration_spec.rb
+++ b/spec/services/notifications/mail_service_mentioned_integration_spec.rb
@@ -32,49 +32,80 @@ require_relative './mentioned_journals_shared'
describe Notifications::MailService, 'Mentioned integration', type: :model do
include_context 'with a mentioned work package being updated again'
+ let(:assignee) do
+ create :user,
+ preferences: {
+ immediate_reminders: {
+ mentioned: true
+ }
+ },
+ notification_settings: [
+ build(:notification_setting,
+ mentioned: true,
+ involved: true)
+ ],
+ member_in_project: project,
+ member_through_role: role
+ end
+
+ let(:assigned_notification) do
+ Notification.find_by(recipient: assignee, journal: work_package.journals.last, reason: :assigned)
+ end
+
def expect_mentioned_notification
expect(mentioned_notification).to be_present
+ mentioned_notification.reload
+ expect(mentioned_notification.recipient).to eq recipient
expect(mentioned_notification.reason).to eq 'mentioned'
expect(mentioned_notification.read_ian).to be false
expect(mentioned_notification.mail_alert_sent).to be true
end
- def expect_mentioned_notification_updated
- old_journal_id = mentioned_notification.journal_id
- mentioned_notification.reload
- expect(mentioned_notification.journal_id).not_to eq old_journal_id
- expect(mentioned_notification.journal).to eq work_package.journals.last
- expect(mentioned_notification.reason).to eq 'mentioned'
- expect(mentioned_notification.read_ian).to be false
- expect(mentioned_notification.mail_alert_sent).to be true
+ def expect_no_assigned_notification
+ expect(Notification.where(recipient:, resource: work_package, reason: :involved))
+ .to be_empty
end
def expect_assigned_notification
expect(assigned_notification).to be_present
+ expect(assigned_notification.recipient).to eq assignee
expect(assigned_notification.read_ian).to be false
expect(assigned_notification.mail_alert_sent).to be false
end
it 'will trigger only one mention notification mail when editing attributes afterwards' do
allow(WorkPackageMailer)
- .to(receive(:mentioned))
- .and_call_original
+ .to receive(:mentioned)
+ .and_call_original
trigger_comment!
expect(WorkPackageMailer)
.to have_received(:mentioned)
- .with(recipient, work_package.journals.last)
+ .with(recipient, work_package.journals.last)
+ .once
+
+ expect_mentioned_notification
+
+ update_assignee!(recipient)
+
+ # No mailing is to be added but the mailing from before still counts.
+ expect(WorkPackageMailer)
+ .to have_received(:mentioned)
+ .once
+ # No involved notification since the assignee is also mentioned which trumps
+ # being assignee and a user will only get one notification for a journal.
+ expect_no_assigned_notification
expect_mentioned_notification
- update_assignee!
+ update_assignee!(assignee)
+ # No mailing is to be added but the mailing from before still counts.
expect(WorkPackageMailer)
- .not_to have_received(:mentioned)
- .with(recipient, work_package.journals.last)
+ .to have_received(:mentioned)
+ .once
- expect_mentioned_notification_updated
expect_assigned_notification
end
end
diff --git a/spec/services/notifications/mentioned_journals_shared.rb b/spec/services/notifications/mentioned_journals_shared.rb
index a8af74844ab..86f19c18a7d 100644
--- a/spec/services/notifications/mentioned_journals_shared.rb
+++ b/spec/services/notifications/mentioned_journals_shared.rb
@@ -73,10 +73,6 @@ shared_context 'with a mentioned work package being updated again' do
Notification.find_by(recipient:, journal: work_package.journals.last, reason: :mentioned)
end
- let(:assigned_notification) do
- Notification.find_by(recipient:, journal: work_package.journals.last, reason: :assigned)
- end
-
def trigger_comment!
User.execute_as(actor) do
work_package.journal_notes = comment
@@ -87,11 +83,11 @@ shared_context 'with a mentioned work package being updated again' do
work_package.reload
end
- def update_assignee!
+ def update_assignee!(assignee_user = recipient)
clear_enqueued_jobs
User.execute_as(actor) do
- work_package.assigned_to = recipient
+ work_package.assigned_to = assignee_user
work_package.save!
end