2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Discussion, ResolvableDiscussion do
|
2017-08-17 22:00:37 +05:30
|
|
|
subject { described_class.new([first_note, second_note, third_note]) }
|
|
|
|
|
|
|
|
let(:first_note) { create(:discussion_note_on_merge_request) }
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:noteable) { first_note.noteable }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { first_note.project }
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:second_note) { create(:discussion_note_on_merge_request, noteable: noteable, project: project, in_reply_to: first_note) }
|
|
|
|
let(:third_note) { create(:discussion_note_on_merge_request, noteable: noteable, project: project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe "#resolvable?" do
|
|
|
|
context "when potentially resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:potentially_resolvable?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when all notes are unresolvable" do
|
|
|
|
before do
|
|
|
|
allow(first_note).to receive(:resolvable?).and_return(false)
|
|
|
|
allow(second_note).to receive(:resolvable?).and_return(false)
|
|
|
|
allow(third_note).to receive(:resolvable?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.resolvable?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when some notes are unresolvable and some notes are resolvable" do
|
|
|
|
before do
|
|
|
|
allow(first_note).to receive(:resolvable?).and_return(true)
|
|
|
|
allow(second_note).to receive(:resolvable?).and_return(false)
|
|
|
|
allow(third_note).to receive(:resolvable?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.resolvable?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when all notes are resolvable" do
|
|
|
|
before do
|
|
|
|
allow(first_note).to receive(:resolvable?).and_return(true)
|
|
|
|
allow(second_note).to receive(:resolvable?).and_return(true)
|
|
|
|
allow(third_note).to receive(:resolvable?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.resolvable?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when not potentially resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:potentially_resolvable?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.resolvable?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#resolved?" do
|
|
|
|
context "when not resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.resolved?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(true)
|
|
|
|
|
|
|
|
allow(first_note).to receive(:resolvable?).and_return(true)
|
|
|
|
allow(second_note).to receive(:resolvable?).and_return(false)
|
|
|
|
allow(third_note).to receive(:resolvable?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when all resolvable notes are resolved" do
|
|
|
|
before do
|
|
|
|
allow(first_note).to receive(:resolved?).and_return(true)
|
|
|
|
allow(third_note).to receive(:resolved?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.resolved?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when some resolvable notes are not resolved" do
|
|
|
|
before do
|
|
|
|
allow(first_note).to receive(:resolved?).and_return(true)
|
|
|
|
allow(third_note).to receive(:resolved?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.resolved?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#to_be_resolved?" do
|
|
|
|
context "when not resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.to_be_resolved?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(true)
|
|
|
|
|
|
|
|
allow(first_note).to receive(:resolvable?).and_return(true)
|
|
|
|
allow(second_note).to receive(:resolvable?).and_return(false)
|
|
|
|
allow(third_note).to receive(:resolvable?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when all resolvable notes are resolved" do
|
|
|
|
before do
|
|
|
|
allow(first_note).to receive(:resolved?).and_return(true)
|
|
|
|
allow(third_note).to receive(:resolved?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.to_be_resolved?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when some resolvable notes are not resolved" do
|
|
|
|
before do
|
|
|
|
allow(first_note).to receive(:resolved?).and_return(true)
|
|
|
|
allow(third_note).to receive(:resolved?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.to_be_resolved?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#can_resolve?" do
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
context "when not resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.can_resolve?(current_user)).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when not signed in" do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.can_resolve?(current_user)).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when signed in" do
|
|
|
|
context "when the signed in user is the noteable author" do
|
|
|
|
before do
|
|
|
|
subject.noteable.author = current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.can_resolve?(current_user)).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the signed in user can push to the project" do
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
subject.project.add_maintainer(current_user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.can_resolve?(current_user)).to be true
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
context "when the noteable has no author" do
|
|
|
|
it "returns true" do
|
|
|
|
expect(noteable).to receive(:author).and_return(nil)
|
|
|
|
expect(subject.can_resolve?(current_user)).to be true
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context "when the signed in user is a random user" do
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.can_resolve?(current_user)).to be false
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
context "when the noteable has no author" do
|
|
|
|
it "returns false" do
|
|
|
|
expect(noteable).to receive(:author).and_return(nil)
|
|
|
|
expect(subject.can_resolve?(current_user)).to be false
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#resolve!" do
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
context "when not resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil" do
|
|
|
|
expect(subject.resolve!(current_user)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't set resolved_at" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
|
|
|
|
expect(subject.resolved_at).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't set resolved_by" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
|
|
|
|
expect(subject.resolved_by).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't mark as resolved" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
|
|
|
|
expect(subject.resolved?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when resolvable" do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:second_note) { create(:diff_note_on_commit) } # unresolvable
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when all resolvable notes are resolved" do
|
|
|
|
before do
|
|
|
|
first_note.resolve!(user)
|
|
|
|
third_note.resolve!(user)
|
|
|
|
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change resolved_at on the resolved notes" do
|
|
|
|
expect(first_note.resolved_at).not_to be_nil
|
|
|
|
expect(third_note.resolved_at).not_to be_nil
|
|
|
|
|
|
|
|
expect { subject.resolve!(current_user) }.not_to change { first_note.resolved_at }
|
|
|
|
expect { subject.resolve!(current_user) }.not_to change { third_note.resolved_at }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change resolved_by on the resolved notes" do
|
|
|
|
expect(first_note.resolved_by).to eq(user)
|
|
|
|
expect(third_note.resolved_by).to eq(user)
|
|
|
|
|
|
|
|
expect { subject.resolve!(current_user) }.not_to change { first_note.resolved_by }
|
|
|
|
expect { subject.resolve!(current_user) }.not_to change { third_note.resolved_by }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change the resolved state on the resolved notes" do
|
|
|
|
expect(first_note.resolved?).to be true
|
|
|
|
expect(third_note.resolved?).to be true
|
|
|
|
|
|
|
|
expect { subject.resolve!(current_user) }.not_to change { first_note.resolved? }
|
|
|
|
expect { subject.resolve!(current_user) }.not_to change { third_note.resolved? }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change resolved_at" do
|
|
|
|
expect(subject.resolved_at).not_to be_nil
|
|
|
|
|
|
|
|
expect { subject.resolve!(current_user) }.not_to change { subject.resolved_at }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change resolved_by" do
|
|
|
|
expect(subject.resolved_by).to eq(user)
|
|
|
|
|
|
|
|
expect { subject.resolve!(current_user) }.not_to change { subject.resolved_by }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change resolved state" do
|
|
|
|
expect(subject.resolved?).to be true
|
|
|
|
|
|
|
|
expect { subject.resolve!(current_user) }.not_to change { subject.resolved? }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when some resolvable notes are resolved" do
|
|
|
|
before do
|
|
|
|
first_note.resolve!(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change resolved_at on the resolved note" do
|
|
|
|
expect(first_note.resolved_at).not_to be_nil
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { subject.resolve!(current_user) }
|
|
|
|
.not_to change { first_note.reload.resolved_at }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change resolved_by on the resolved note" do
|
|
|
|
expect(first_note.resolved_by).to eq(user)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { subject.resolve!(current_user) }
|
|
|
|
.not_to change { first_note.reload && first_note.resolved_by }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't change the resolved state on the resolved note" do
|
|
|
|
expect(first_note.resolved?).to be true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { subject.resolve!(current_user) }
|
|
|
|
.not_to change { first_note.reload && first_note.resolved? }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets resolved_at on the unresolved note" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(third_note.resolved_at).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets resolved_by on the unresolved note" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(third_note.resolved_by).to eq(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "marks the unresolved note as resolved" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(third_note.resolved?).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets resolved_at" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
|
|
|
|
expect(subject.resolved_at).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets resolved_by" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
|
|
|
|
expect(subject.resolved_by).to eq(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "marks as resolved" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
|
|
|
|
expect(subject.resolved?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no resolvable notes are resolved" do
|
|
|
|
it "sets resolved_at on the unresolved notes" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(first_note.resolved_at).not_to be_nil
|
|
|
|
expect(third_note.resolved_at).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets resolved_by on the unresolved notes" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(first_note.resolved_by).to eq(current_user)
|
|
|
|
expect(third_note.resolved_by).to eq(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "marks the unresolved notes as resolved" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(first_note.resolved?).to be true
|
|
|
|
expect(third_note.resolved?).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets resolved_at" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(subject.resolved_at).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets resolved_by" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(subject.resolved_by).to eq(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "marks as resolved" do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(subject.resolved?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#unresolve!" do
|
|
|
|
context "when not resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil" do
|
|
|
|
expect(subject.unresolve!).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when resolvable" do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(true)
|
|
|
|
|
|
|
|
allow(first_note).to receive(:resolvable?).and_return(true)
|
|
|
|
allow(second_note).to receive(:resolvable?).and_return(false)
|
|
|
|
allow(third_note).to receive(:resolvable?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when all resolvable notes are resolved" do
|
|
|
|
before do
|
|
|
|
first_note.resolve!(user)
|
|
|
|
third_note.resolve!(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unsets resolved_at on the resolved notes" do
|
|
|
|
subject.unresolve!
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(first_note.resolved_at).to be_nil
|
|
|
|
expect(third_note.resolved_at).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unsets resolved_by on the resolved notes" do
|
|
|
|
subject.unresolve!
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(first_note.resolved_by).to be_nil
|
|
|
|
expect(third_note.resolved_by).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unmarks the resolved notes as resolved" do
|
|
|
|
subject.unresolve!
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(first_note.resolved?).to be false
|
|
|
|
expect(third_note.resolved?).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unsets resolved_at" do
|
|
|
|
subject.unresolve!
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(subject.resolved_at).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unsets resolved_by" do
|
|
|
|
subject.unresolve!
|
|
|
|
first_note.reload
|
|
|
|
third_note.reload
|
|
|
|
|
|
|
|
expect(subject.resolved_by).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unmarks as resolved" do
|
|
|
|
subject.unresolve!
|
|
|
|
|
|
|
|
expect(subject.resolved?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when some resolvable notes are resolved" do
|
|
|
|
before do
|
|
|
|
first_note.resolve!(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unsets resolved_at on the resolved note" do
|
|
|
|
subject.unresolve!
|
|
|
|
|
|
|
|
expect(subject.first_note.resolved_at).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unsets resolved_by on the resolved note" do
|
|
|
|
subject.unresolve!
|
|
|
|
|
|
|
|
expect(subject.first_note.resolved_by).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unmarks the resolved note as resolved" do
|
|
|
|
subject.unresolve!
|
|
|
|
|
|
|
|
expect(subject.first_note.resolved?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#first_note_to_resolve" do
|
|
|
|
it "returns the first note that still needs to be resolved" do
|
|
|
|
allow(first_note).to receive(:to_be_resolved?).and_return(false)
|
|
|
|
allow(second_note).to receive(:to_be_resolved?).and_return(true)
|
|
|
|
|
|
|
|
expect(subject.first_note_to_resolve).to eq(second_note)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#last_resolved_note" do
|
|
|
|
let(:current_user) { create(:user) }
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:time) { Time.current.utc }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before do
|
2018-11-08 19:23:39 +05:30
|
|
|
Timecop.freeze(time - 1.second) do
|
|
|
|
first_note.resolve!(current_user)
|
|
|
|
end
|
|
|
|
Timecop.freeze(time) do
|
|
|
|
third_note.resolve!(current_user)
|
|
|
|
end
|
|
|
|
Timecop.freeze(time + 1.second) do
|
|
|
|
second_note.resolve!(current_user)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the last note that was resolved" do
|
|
|
|
expect(subject.last_resolved_note).to eq(second_note)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|