Commit 5ea33f64 authored by Peter Leitzen's avatar Peter Leitzen

Speed up notification service specs

parent 028bfb11
...@@ -286,10 +286,10 @@ RSpec.describe NotificationService, :mailer do ...@@ -286,10 +286,10 @@ RSpec.describe NotificationService, :mailer do
describe 'Notes' do describe 'Notes' do
context 'issue note' do context 'issue note' do
let(:project) { create(:project, :private) } let_it_be(:project) { create(:project, :private) }
let(:issue) { create(:issue, project: project, assignees: [assignee]) } let_it_be(:issue) { create(:issue, project: project, assignees: [assignee]) }
let(:mentioned_issue) { create(:issue, assignees: issue.assignees) } let_it_be(:mentioned_issue) { create(:issue, assignees: issue.assignees) }
let(:author) { create(:user) } let_it_be_with_reload(:author) { create(:user) }
let(:note) { create(:note_on_issue, author: author, noteable: issue, project_id: issue.project_id, note: '@mention referenced, @unsubscribed_mentioned and @outsider also') } let(:note) { create(:note_on_issue, author: author, noteable: issue, project_id: issue.project_id, note: '@mention referenced, @unsubscribed_mentioned and @outsider also') }
subject { notification.new_note(note) } subject { notification.new_note(note) }
...@@ -368,7 +368,7 @@ RSpec.describe NotificationService, :mailer do ...@@ -368,7 +368,7 @@ RSpec.describe NotificationService, :mailer do
end end
describe '#new_note' do describe '#new_note' do
before do before_all do
build_team(project) build_team(project)
project.add_maintainer(issue.author) project.add_maintainer(issue.author)
project.add_maintainer(assignee) project.add_maintainer(assignee)
...@@ -390,9 +390,12 @@ RSpec.describe NotificationService, :mailer do ...@@ -390,9 +390,12 @@ RSpec.describe NotificationService, :mailer do
end end
context 'with users' do context 'with users' do
before do before_all do
add_users(project) add_users(project)
add_user_subscriptions(issue) add_user_subscriptions(issue)
end
before do
reset_delivered_emails! reset_delivered_emails!
end end
...@@ -569,17 +572,20 @@ RSpec.describe NotificationService, :mailer do ...@@ -569,17 +572,20 @@ RSpec.describe NotificationService, :mailer do
end end
context 'issue note mention', :deliver_mails_inline do context 'issue note mention', :deliver_mails_inline do
let(:issue) { create(:issue, project: project, assignees: [assignee]) } let_it_be(:issue) { create(:issue, project: project, assignees: [assignee]) }
let(:mentioned_issue) { create(:issue, assignees: issue.assignees) } let_it_be(:mentioned_issue) { create(:issue, assignees: issue.assignees) }
let(:author) { create(:user) } let_it_be(:author) { create(:user) }
let(:note) { create(:note_on_issue, author: author, noteable: issue, project_id: issue.project_id, note: '@all mentioned') } let(:note) { create(:note_on_issue, author: author, noteable: issue, project_id: issue.project_id, note: '@all mentioned') }
before do before_all do
build_team(project) build_team(project)
build_group(project) build_group(project)
add_users(project) add_users(project)
add_user_subscriptions(issue) add_user_subscriptions(issue)
project.add_maintainer(author) project.add_maintainer(author)
end
before do
reset_delivered_emails! reset_delivered_emails!
end end
...@@ -726,18 +732,21 @@ RSpec.describe NotificationService, :mailer do ...@@ -726,18 +732,21 @@ RSpec.describe NotificationService, :mailer do
end end
context 'commit note', :deliver_mails_inline do context 'commit note', :deliver_mails_inline do
let(:project) { create(:project, :public, :repository) } let_it_be(:project) { create(:project, :public, :repository) }
let(:note) { create(:note_on_commit, project: project) } let_it_be(:note) { create(:note_on_commit, project: project) }
before do before_all do
build_team(project) build_team(project)
build_group(project) build_group(project)
reset_delivered_emails!
allow(note.noteable).to receive(:author).and_return(@u_committer)
update_custom_notification(:new_note, @u_guest_custom, resource: project) update_custom_notification(:new_note, @u_guest_custom, resource: project)
update_custom_notification(:new_note, @u_custom_global) update_custom_notification(:new_note, @u_custom_global)
end end
before do
reset_delivered_emails!
allow(note.noteable).to receive(:author).and_return(@u_committer)
end
describe '#new_note, #perform_enqueued_jobs' do describe '#new_note, #perform_enqueued_jobs' do
it do it do
notification.new_note(note) notification.new_note(note)
...@@ -785,12 +794,12 @@ RSpec.describe NotificationService, :mailer do ...@@ -785,12 +794,12 @@ RSpec.describe NotificationService, :mailer do
end end
context "merge request diff note", :deliver_mails_inline do context "merge request diff note", :deliver_mails_inline do
let(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:merge_request) { create(:merge_request, source_project: project, assignees: [user], author: create(:user)) } let_it_be(:merge_request) { create(:merge_request, source_project: project, assignees: [user], author: create(:user)) }
let(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request) } let_it_be(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request) }
before do before_all do
build_team(note.project) build_team(note.project)
project.add_maintainer(merge_request.author) project.add_maintainer(merge_request.author)
merge_request.assignees.each { |assignee| project.add_maintainer(assignee) } merge_request.assignees.each { |assignee| project.add_maintainer(assignee) }
...@@ -2521,15 +2530,15 @@ RSpec.describe NotificationService, :mailer do ...@@ -2521,15 +2530,15 @@ RSpec.describe NotificationService, :mailer do
describe 'Pipelines', :deliver_mails_inline do describe 'Pipelines', :deliver_mails_inline do
describe '#pipeline_finished' do describe '#pipeline_finished' do
let(:project) { create(:project, :public, :repository) } let_it_be(:project) { create(:project, :public, :repository) }
let(:u_member) { create(:user) } let_it_be(:u_member) { create(:user) }
let(:u_watcher) { create_user_with_notification(:watch, 'watcher') } let_it_be(:u_watcher) { create_user_with_notification(:watch, 'watcher') }
let(:u_custom_notification_unset) do let_it_be(:u_custom_notification_unset) do
create_user_with_notification(:custom, 'custom_unset') create_user_with_notification(:custom, 'custom_unset')
end end
let(:u_custom_notification_enabled) do let_it_be(:u_custom_notification_enabled) do
user = create_user_with_notification(:custom, 'custom_enabled') user = create_user_with_notification(:custom, 'custom_enabled')
update_custom_notification(:success_pipeline, user, resource: project) update_custom_notification(:success_pipeline, user, resource: project)
update_custom_notification(:failed_pipeline, user, resource: project) update_custom_notification(:failed_pipeline, user, resource: project)
...@@ -2537,7 +2546,7 @@ RSpec.describe NotificationService, :mailer do ...@@ -2537,7 +2546,7 @@ RSpec.describe NotificationService, :mailer do
user user
end end
let(:u_custom_notification_disabled) do let_it_be(:u_custom_notification_disabled) do
user = create_user_with_notification(:custom, 'custom_disabled') user = create_user_with_notification(:custom, 'custom_disabled')
update_custom_notification(:success_pipeline, user, resource: project, value: false) update_custom_notification(:success_pipeline, user, resource: project, value: false)
update_custom_notification(:failed_pipeline, user, resource: project, value: false) update_custom_notification(:failed_pipeline, user, resource: project, value: false)
...@@ -2556,13 +2565,15 @@ RSpec.describe NotificationService, :mailer do ...@@ -2556,13 +2565,15 @@ RSpec.describe NotificationService, :mailer do
before_sha: '00000000') before_sha: '00000000')
end end
before do before_all do
project.add_maintainer(u_member) project.add_maintainer(u_member)
project.add_maintainer(u_watcher) project.add_maintainer(u_watcher)
project.add_maintainer(u_custom_notification_unset) project.add_maintainer(u_custom_notification_unset)
project.add_maintainer(u_custom_notification_enabled) project.add_maintainer(u_custom_notification_enabled)
project.add_maintainer(u_custom_notification_disabled) project.add_maintainer(u_custom_notification_disabled)
end
before do
reset_delivered_emails! reset_delivered_emails!
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment