Commit 41007f6d authored by Douwe Maan's avatar Douwe Maan
Browse files

Address review feedback

parent 3c8d9d770083
......@@ -9,7 +9,7 @@ def resolve
discussion.resolve!(current_user)
MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(merge_request)
MergeRequests::ResolvedDiscussionNotificationService.new(project, current_user).execute(merge_request)
render json: {
resolved_by: discussion.resolved_by.try(:name),
......
......@@ -72,7 +72,7 @@ def resolve
note.resolve!(current_user)
MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(note.noteable)
MergeRequests::ResolvedDiscussionNotificationService.new(project, current_user).execute(note.noteable)
discussion = note.discussion
......@@ -166,7 +166,7 @@ def note_json(note)
}
if note.diff_note?
discussion = note.as_discussion
discussion = note.to_discussion
attrs.merge!(
diff_discussion_html: diff_discussion_html(discussion),
......
......@@ -113,7 +113,7 @@ def discussion
Discussion.new(discussion_notes)
end
def as_discussion
def to_discussion
Discussion.new([self])
end
......
......@@ -57,6 +57,8 @@ def last_updated_by
def id
first_note.discussion_id
end
alias_method :to_param, :id
def diff_discussion?
first_note.diff_note?
......
module MergeRequests
class AllDiscussionsResolvedService < MergeRequests::BaseService
class ResolvedDiscussionNotificationService < MergeRequests::BaseService
def execute(merge_request)
return unless merge_request.discussions_resolved?
......
......@@ -5,6 +5,16 @@
let(:project) { create(:project) }
let(:merge_request) { create(:merge_request, source_project: project) }
let(:note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project) }
let(:discussion) { note.discussion }
let(:request_params) do
{
namespace_id: project.namespace,
project_id: project,
merge_request_id: merge_request,
id: note.discussion_id
}
end
describe 'POST resolve' do
before do
......@@ -13,7 +23,7 @@
context "when the user is not authorized to resolve the discussion" do
it "returns status 404" do
post :resolve, namespace_id: project.namespace.path, project_id: project.path, merge_request_id: merge_request.iid, id: note.discussion_id
post :resolve, request_params
expect(response).to have_http_status(404)
end
......@@ -30,7 +40,7 @@
end
it "returns status 404" do
post :resolve, namespace_id: project.namespace.path, project_id: project.path, merge_request_id: merge_request.iid, id: note.discussion_id
post :resolve, request_params
expect(response).to have_http_status(404)
end
......@@ -38,25 +48,26 @@
context "when the discussion is resolvable" do
it "resolves the discussion" do
expect_any_instance_of(Discussion).to receive(:resolve!).with(user)
post :resolve, request_params
post :resolve, namespace_id: project.namespace.path, project_id: project.path, merge_request_id: merge_request.iid, id: note.discussion_id
expect(note.reload.discussion.resolved?).to be true
expect(note.reload.discussion.resolved_by).to eq(user)
end
it "checks whether all notes are resolved" do
expect_any_instance_of(MergeRequests::AllDiscussionsResolvedService).to receive(:execute).with(merge_request)
it "sends notifications if all discussions are resolved" do
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(merge_request)
post :resolve, namespace_id: project.namespace.path, project_id: project.path, merge_request_id: merge_request.iid, id: note.discussion_id
post :resolve, request_params
end
it "returns the name of the resolving user" do
post :resolve, namespace_id: project.namespace.path, project_id: project.path, merge_request_id: merge_request.iid, id: note.discussion_id
post :resolve, request_params
expect(JSON.parse(response.body)["resolved_by"]).to eq(user.name)
end
it "returns status 200" do
post :resolve, namespace_id: project.namespace.path, project_id: project.path, merge_request_id: merge_request.iid, id: note.discussion_id
post :resolve, request_params
expect(response).to have_http_status(200)
end
......@@ -67,11 +78,13 @@
describe 'DELETE unresolve' do
before do
sign_in user
note.discussion.resolve!(user)
end
context "when the user is not authorized to resolve the discussion" do
it "returns status 404" do
delete :unresolve, namespace_id: project.namespace.path, project_id: project.path, merge_request_id: merge_request.iid, id: note.discussion_id
delete :unresolve, request_params
expect(response).to have_http_status(404)
end
......@@ -88,7 +101,7 @@
end
it "returns status 404" do
delete :unresolve, namespace_id: project.namespace.path, project_id: project.path, merge_request_id: merge_request.iid, id: note.discussion_id
delete :unresolve, request_params
expect(response).to have_http_status(404)
end
......@@ -96,13 +109,13 @@
context "when the discussion is resolvable" do
it "unresolves the discussion" do
expect_any_instance_of(Discussion).to receive(:unresolve!)
delete :unresolve, request_params
delete :unresolve, namespace_id: project.namespace.path, project_id: project.path, merge_request_id: merge_request.iid, id: note.discussion_id
expect(note.reload.discussion.resolved?).to be false
end
it "returns status 200" do
delete :unresolve, namespace_id: project.namespace.path, project_id: project.path, merge_request_id: merge_request.iid, id: note.discussion_id
delete :unresolve, request_params
expect(response).to have_http_status(200)
end
......
......@@ -6,6 +6,14 @@
let(:issue) { create(:issue, project: project) }
let(:note) { create(:note, noteable: issue, project: project) }
let(:request_params) do
{
namespace_id: project.namespace,
project_id: project,
id: note
}
end
describe 'POST toggle_award_emoji' do
before do
sign_in(user)
......@@ -14,123 +22,130 @@
it "toggles the award emoji" do
expect do
post(:toggle_award_emoji, namespace_id: project.namespace.path,
project_id: project.path, id: note.id, name: "thumbsup")
post(:toggle_award_emoji, request_params.merge(name: "thumbsup"))
end.to change { note.award_emoji.count }.by(1)
expect(response).to have_http_status(200)
end
it "removes the already awarded emoji" do
post(:toggle_award_emoji, namespace_id: project.namespace.path,
project_id: project.path, id: note.id, name: "thumbsup")
post(:toggle_award_emoji, request_params.merge(name: "thumbsup"))
expect do
post(:toggle_award_emoji, namespace_id: project.namespace.path,
project_id: project.path, id: note.id, name: "thumbsup")
post(:toggle_award_emoji, request_params.merge(name: "thumbsup"))
end.to change { AwardEmoji.count }.by(-1)
expect(response).to have_http_status(200)
end
end
describe 'POST resolve' do
before do
sign_in user
end
describe "resolving and unresolving" do
let(:merge_request) { create(:merge_request, source_project: project) }
let(:note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project) }
context "when the user is not authorized to resolve the note" do
it "returns status 404" do
post :resolve, namespace_id: project.namespace.path, project_id: project.path, id: note.id
expect(response).to have_http_status(404)
end
end
context "when the user is authorized to resolve the note" do
describe 'POST resolve' do
before do
project.team << [user, :developer]
sign_in user
end
context "when the note is not resolvable" do
context "when the user is not authorized to resolve the note" do
it "returns status 404" do
post :resolve, namespace_id: project.namespace.path, project_id: project.path, id: note.id
post :resolve, request_params
expect(response).to have_http_status(404)
end
end
context "when the note is resolvable" do
let(:merge_request) { create(:merge_request, source_project: project) }
let(:note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project) }
it "resolves the note" do
expect_any_instance_of(DiffNote).to receive(:resolve!).with(user)
post :resolve, namespace_id: project.namespace.path, project_id: project.path, id: note.id
context "when the user is authorized to resolve the note" do
before do
project.team << [user, :developer]
end
it "checks whether all notes are resolved" do
expect_any_instance_of(MergeRequests::AllDiscussionsResolvedService).to receive(:execute).with(merge_request)
context "when the note is not resolvable" do
before do
note.update(system: true)
end
post :resolve, namespace_id: project.namespace.path, project_id: project.path, id: note.id
it "returns status 404" do
post :resolve, request_params
expect(response).to have_http_status(404)
end
end
it "returns the name of the resolving user" do
post :resolve, namespace_id: project.namespace.path, project_id: project.path, id: note.id
context "when the note is resolvable" do
it "resolves the note" do
post :resolve, request_params
expect(JSON.parse(response.body)["resolved_by"]).to eq(user.name)
end
expect(note.reload.resolved?).to be true
expect(note.reload.resolved_by).to eq(user)
end
it "returns status 200" do
post :resolve, namespace_id: project.namespace.path, project_id: project.path, id: note.id
it "sends notifications if all discussions are resolved" do
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(merge_request)
expect(response).to have_http_status(200)
end
end
end
end
post :resolve, request_params
end
describe 'DELETE unresolve' do
before do
sign_in user
end
it "returns the name of the resolving user" do
post :resolve, request_params
expect(JSON.parse(response.body)["resolved_by"]).to eq(user.name)
end
context "when the user is not authorized to resolve the note" do
it "returns status 404" do
delete :unresolve, namespace_id: project.namespace.path, project_id: project.path, id: note.id
it "returns status 200" do
post :resolve, request_params
expect(response).to have_http_status(404)
expect(response).to have_http_status(200)
end
end
end
end
context "when the user is authorized to resolve the note" do
describe 'DELETE unresolve' do
before do
project.team << [user, :developer]
sign_in user
note.resolve!(user)
end
context "when the note is not resolvable" do
context "when the user is not authorized to resolve the note" do
it "returns status 404" do
delete :unresolve, namespace_id: project.namespace.path, project_id: project.path, id: note.id
delete :unresolve, request_params
expect(response).to have_http_status(404)
end
end
context "when the note is resolvable" do
let(:merge_request) { create(:merge_request, source_project: project) }
let(:note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project) }
context "when the user is authorized to resolve the note" do
before do
project.team << [user, :developer]
end
context "when the note is not resolvable" do
before do
note.update(system: true)
end
it "unresolves the note" do
expect_any_instance_of(DiffNote).to receive(:unresolve!)
it "returns status 404" do
delete :unresolve, request_params
delete :unresolve, namespace_id: project.namespace.path, project_id: project.path, id: note.id
expect(response).to have_http_status(404)
end
end
it "returns status 200" do
delete :unresolve, namespace_id: project.namespace.path, project_id: project.path, id: note.id
context "when the note is resolvable" do
it "unresolves the note" do
delete :unresolve, request_params
expect(note.reload.resolved?).to be false
end
it "returns status 200" do
delete :unresolve, request_params
expect(response).to have_http_status(200)
expect(response).to have_http_status(200)
end
end
end
end
......
......@@ -103,7 +103,7 @@
describe "#active?" do
context "when noteable is a commit" do
subject { create(:diff_note_on_commit, project: project, position: position) }
subject { build(:diff_note_on_commit, project: project, position: position) }
it "returns true" do
expect(subject.active?).to be true
......
require 'spec_helper'
describe MergeRequests::AllDiscussionsResolvedService, services: true do
describe MergeRequests::ResolvedDiscussionNotificationService, services: true do
let(:merge_request) { create(:merge_request) }
let(:user) { create(:user) }
let(:project) { merge_request.project }
......
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