gitlab-org--gitlab-foss/spec/services/discussions/resolve_service_spec.rb
Bob Van Landuyt 1123057ab7 Feature: delegate all open discussions to Issue
When a merge request can only be merged when all discussions are
resolved. This feature allows to easily delegate those discussions to a
new issue, while marking them as resolved in the merge request.

The user is presented with a new issue, prepared with mentions of all
unresolved discussions, including the first unresolved note of the
discussion, time and link to the note.

When the issue is created, the discussions in the merge request will get
a system note directing the user to the newly created issue.
2016-12-05 20:55:45 +01:00

52 lines
1.8 KiB
Ruby

require 'spec_helper'
describe Discussions::ResolveService do
describe '#execute' do
let(:discussion) { Discussion.for_diff_notes([create(:diff_note_on_merge_request)]).first }
let(:project) { merge_request.project }
let(:merge_request) { discussion.noteable }
let(:user) { create(:user) }
let(:service) { described_class.new(discussion.noteable.project, user, merge_request: merge_request) }
before do
project.team << [user, :master]
end
it "doesn't resolve discussions the user can't resolve" do
expect(discussion).to receive(:can_resolve?).with(user).and_return(false)
service.execute(discussion)
expect(discussion.resolved?).to be(false)
end
it 'resolves the discussion' do
service.execute(discussion)
expect(discussion.resolved?).to be(true)
end
it 'executes the notification service' do
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(discussion.noteable)
service.execute(discussion)
end
it 'adds a system note to the discussion' do
issue = create(:issue, project: project)
expect(SystemNoteService).to receive(:discussion_continued_in_issue).with(discussion, project, user, issue)
service = described_class.new(project, user, merge_request: merge_request, follow_up_issue: issue)
service.execute(discussion)
end
it 'can resolve multiple discussions at once' do
other_discussion = Discussion.for_diff_notes([create(:diff_note_on_merge_request, noteable: discussion.noteable, project: discussion.noteable.source_project)]).first
service.execute([discussion, other_discussion])
expect(discussion.resolved?).to be(true)
expect(other_discussion.resolved?).to be(true)
end
end
end