debian-mirror-gitlab/spec/services/notification_recipients/build_service_spec.rb

62 lines
1.7 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require 'spec_helper'
2020-04-08 14:13:33 +05:30
describe NotificationRecipients::BuildService do
2018-11-08 19:23:39 +05:30
let(:service) { described_class }
let(:assignee) { create(:user) }
let(:project) { create(:project, :public) }
let(:other_projects) { create_list(:project, 5, :public) }
describe '#build_new_note_recipients' do
let(:issue) { create(:issue, project: project, assignees: [assignee]) }
let(:note) { create(:note_on_issue, noteable: issue, project_id: issue.project_id) }
2018-12-05 23:21:45 +05:30
shared_examples 'no N+1 queries' do
it 'avoids N+1 queries', :request_store do
create_user
2018-11-08 19:23:39 +05:30
2018-12-05 23:21:45 +05:30
service.build_new_note_recipients(note)
control_count = ActiveRecord::QueryRecorder.new do
service.build_new_note_recipients(note)
end
create_user
expect { service.build_new_note_recipients(note) }.not_to exceed_query_limit(control_count)
2018-11-08 19:23:39 +05:30
end
end
2018-12-05 23:21:45 +05:30
context 'when there are multiple watchers' do
def create_user
watcher = create(:user)
create(:notification_setting, source: project, user: watcher, level: :watch)
other_projects.each do |other_project|
create(:notification_setting, source: other_project, user: watcher, level: :watch)
end
end
2018-11-08 19:23:39 +05:30
2018-12-05 23:21:45 +05:30
include_examples 'no N+1 queries'
end
2018-11-08 19:23:39 +05:30
2018-12-05 23:21:45 +05:30
context 'when there are multiple subscribers' do
def create_user
subscriber = create(:user)
issue.subscriptions.create(user: subscriber, project: project, subscribed: true)
2018-11-08 19:23:39 +05:30
end
2018-12-05 23:21:45 +05:30
include_examples 'no N+1 queries'
2018-11-08 19:23:39 +05:30
2018-12-05 23:21:45 +05:30
context 'when the project is private' do
before do
project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
end
include_examples 'no N+1 queries'
end
2018-11-08 19:23:39 +05:30
end
end
end