2018-06-07 07:14:27 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe NotificationRecipientService do
|
|
|
|
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) }
|
|
|
|
|
|
|
|
def create_watcher
|
|
|
|
watcher = create(:user)
|
2018-07-04 11:12:37 -04:00
|
|
|
create(:notification_setting, source: project, user: watcher, level: :watch)
|
2018-06-07 07:14:27 -04:00
|
|
|
|
|
|
|
other_projects.each do |other_project|
|
2018-07-04 11:12:37 -04:00
|
|
|
create(:notification_setting, source: other_project, user: watcher, level: :watch)
|
2018-06-07 07:14:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-08 06:45:36 -04:00
|
|
|
it 'avoids N+1 queries', :request_store do
|
2018-07-04 11:12:37 -04:00
|
|
|
create_watcher
|
2018-06-07 07:14:27 -04:00
|
|
|
|
|
|
|
service.build_new_note_recipients(note)
|
|
|
|
|
|
|
|
control_count = ActiveRecord::QueryRecorder.new do
|
|
|
|
service.build_new_note_recipients(note)
|
|
|
|
end
|
|
|
|
|
2018-07-04 11:12:37 -04:00
|
|
|
create_watcher
|
2018-06-07 07:14:27 -04:00
|
|
|
|
|
|
|
expect { service.build_new_note_recipients(note) }.not_to exceed_query_limit(control_count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|