Commit 9d9b7212 authored by Douwe Maan's avatar Douwe Maan

Add specs for system note and email when all discussions are resolved

parent e2572004
require 'spec_helper'
require 'email_spec'
require 'mailers/shared/notify'
describe Notify, "merge request notifications" do
include EmailSpec::Matchers
describe "#resolved_all_discussions_email" do
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request) }
let(:current_user) { create(:user) }
subject { Notify.resolved_all_discussions_email(user.id, merge_request.id, current_user.id) }
it "includes the name of the resolver" do
expect(subject).to have_body_text current_user.name
end
end
end
require 'spec_helper'
describe MergeRequests::AllDiscussionsResolvedService, services: true do
let(:merge_request) { create(:merge_request) }
let(:user) { create(:user) }
let(:project) { merge_request.project }
subject { described_class.new(project, user) }
describe "#execute" do
context "when not all discussions are resolved" do
before do
allow(merge_request).to receive(:discussions_resolved?).and_return(false)
end
it "doesn't add a system note" do
expect(SystemNoteService).not_to receive(:resolve_all_discussions)
subject.execute(merge_request)
end
it "doesn't send a notification email" do
expect_any_instance_of(NotificationService).not_to receive(:resolve_all_discussions)
subject.execute(merge_request)
end
end
context "when all discussions are resolved" do
before do
allow(merge_request).to receive(:discussions_resolved?).and_return(true)
end
it "adds a system note" do
expect(SystemNoteService).to receive(:resolve_all_discussions).with(merge_request, project, user)
subject.execute(merge_request)
end
it "sends a notification email" do
expect_any_instance_of(NotificationService).to receive(:resolve_all_discussions).with(merge_request, user)
subject.execute(merge_request)
end
end
end
end
......@@ -1004,6 +1004,52 @@ describe NotificationService, services: true do
end
end
end
describe "#resolve_all_discussions" do
it do
notification.resolve_all_discussions(merge_request, @u_disabled)
should_email(merge_request.assignee)
should_email(@u_watcher)
should_email(@u_participant_mentioned)
should_email(@subscriber)
should_email(@watcher_and_subscriber)
should_email(@u_guest_watcher)
should_not_email(@unsubscriber)
should_not_email(@u_participating)
should_not_email(@u_disabled)
should_not_email(@u_lazy_participant)
end
context 'participating' do
context 'by assignee' do
before do
merge_request.update_attribute(:assignee, @u_lazy_participant)
notification.resolve_all_discussions(merge_request, @u_disabled)
end
it { should_email(@u_lazy_participant) }
end
context 'by note' do
let!(:note) { create(:note_on_issue, noteable: merge_request, project_id: project.id, note: 'anything', author: @u_lazy_participant) }
before { notification.resolve_all_discussions(merge_request, @u_disabled) }
it { should_email(@u_lazy_participant) }
end
context 'by author' do
before do
merge_request.author = @u_lazy_participant
merge_request.save
notification.resolve_all_discussions(merge_request, @u_disabled)
end
it { should_email(@u_lazy_participant) }
end
end
end
end
describe 'Projects' do
......
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