2017-03-09 20:29:11 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Note, ResolvableNote do
|
2017-08-01 14:51:52 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2017-04-04 18:27:23 -04:00
|
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
subject { create(:discussion_note_on_merge_request, noteable: merge_request, project: project) }
|
2017-03-09 20:29:11 -05:00
|
|
|
|
2017-03-17 15:25:52 -04:00
|
|
|
context 'resolvability scopes' do
|
2017-04-04 18:27:23 -04:00
|
|
|
let!(:note1) { create(:note, project: project) }
|
|
|
|
let!(:note2) { create(:diff_note_on_commit, project: project) }
|
|
|
|
let!(:note3) { create(:diff_note_on_merge_request, :resolved, noteable: merge_request, project: project) }
|
|
|
|
let!(:note4) { create(:discussion_note_on_merge_request, noteable: merge_request, project: project) }
|
|
|
|
let!(:note5) { create(:discussion_note_on_issue, project: project) }
|
|
|
|
let!(:note6) { create(:discussion_note_on_merge_request, :system, noteable: merge_request, project: project) }
|
2017-03-17 15:25:52 -04:00
|
|
|
|
|
|
|
describe '.potentially_resolvable' do
|
|
|
|
it 'includes diff and discussion notes on merge requests' do
|
|
|
|
expect(Note.potentially_resolvable).to match_array([note3, note4, note6])
|
|
|
|
end
|
|
|
|
end
|
2017-03-09 20:29:11 -05:00
|
|
|
|
2017-03-17 15:25:52 -04:00
|
|
|
describe '.resolvable' do
|
|
|
|
it 'includes non-system diff and discussion notes on merge requests' do
|
|
|
|
expect(Note.resolvable).to match_array([note3, note4])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.resolved' do
|
|
|
|
it 'includes resolved non-system diff and discussion notes on merge requests' do
|
|
|
|
expect(Note.resolved).to match_array([note3])
|
|
|
|
end
|
|
|
|
end
|
2017-03-09 20:29:11 -05:00
|
|
|
|
2017-03-17 15:25:52 -04:00
|
|
|
describe '.unresolved' do
|
|
|
|
it 'includes non-resolved non-system diff and discussion notes on merge requests' do
|
|
|
|
expect(Note.unresolved).to match_array([note4])
|
|
|
|
end
|
|
|
|
end
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe ".resolve!" do
|
|
|
|
let(:current_user) { create(:user) }
|
2017-04-04 18:27:23 -04:00
|
|
|
let!(:commit_note) { create(:diff_note_on_commit, project: project) }
|
|
|
|
let!(:resolved_note) { create(:discussion_note_on_merge_request, :resolved, noteable: merge_request, project: project) }
|
|
|
|
let!(:unresolved_note) { create(:discussion_note_on_merge_request, noteable: merge_request, project: project) }
|
2017-03-09 20:29:11 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
described_class.resolve!(current_user)
|
|
|
|
|
|
|
|
commit_note.reload
|
|
|
|
resolved_note.reload
|
|
|
|
unresolved_note.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'resolves only the resolvable, not yet resolved notes' do
|
|
|
|
expect(commit_note.resolved_at).to be_nil
|
|
|
|
expect(resolved_note.resolved_by).not_to eq(current_user)
|
|
|
|
expect(unresolved_note.resolved_at).not_to be_nil
|
|
|
|
expect(unresolved_note.resolved_by).to eq(current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".unresolve!" do
|
2017-04-04 18:27:23 -04:00
|
|
|
let!(:resolved_note) { create(:discussion_note_on_merge_request, :resolved, noteable: merge_request, project: project) }
|
2017-03-09 20:29:11 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
described_class.unresolve!
|
|
|
|
|
|
|
|
resolved_note.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'unresolves the resolved notes' do
|
|
|
|
expect(resolved_note.resolved_by).to be_nil
|
|
|
|
expect(resolved_note.resolved_at).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resolvable?' do
|
|
|
|
context "when potentially resolvable" do
|
|
|
|
before do
|
2017-03-17 15:25:52 -04:00
|
|
|
allow(subject).to receive(:potentially_resolvable?).and_return(true)
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when a system note" do
|
|
|
|
before do
|
|
|
|
subject.system = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.resolvable?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when a regular note" do
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.resolvable?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when not potentially resolvable" do
|
|
|
|
before do
|
2017-03-17 15:25:52 -04:00
|
|
|
allow(subject).to receive(:potentially_resolvable?).and_return(false)
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.resolvable?).to be false
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when resolved" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolved?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.to_be_resolved?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when not resolved" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolved?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.to_be_resolved?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#resolved?" do
|
2017-03-17 15:25:52 -04:00
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
context 'when not resolvable' do
|
|
|
|
before do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.resolved?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when resolvable' do
|
|
|
|
context 'when the note has been resolved' do
|
|
|
|
before do
|
|
|
|
subject.resolve!(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject.resolved?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the note has not been resolved' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.resolved?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-09 20:29:11 -05:00
|
|
|
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
|
|
|
|
|
2017-09-05 13:51:08 -04:00
|
|
|
it "returns false" do
|
|
|
|
expect(subject.resolve!(current_user)).to be_falsey
|
2017-03-09 20:29:11 -05:00
|
|
|
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
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when already resolved" do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.resolve!(user)
|
|
|
|
end
|
|
|
|
|
2017-09-05 13:51:08 -04:00
|
|
|
it "returns false" do
|
|
|
|
expect(subject.resolve!(current_user)).to be_falsey
|
2017-03-09 20:29:11 -05:00
|
|
|
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 status" do
|
|
|
|
expect(subject.resolved?).to be true
|
|
|
|
|
|
|
|
expect { subject.resolve!(current_user) }.not_to change { subject.resolved? }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when not yet resolved" do
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.resolve!(current_user)).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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#unresolve!" do
|
|
|
|
context "when not resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(false)
|
|
|
|
end
|
|
|
|
|
2017-09-05 13:51:08 -04:00
|
|
|
it "returns false" do
|
|
|
|
expect(subject.unresolve!).to be_falsey
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when resolvable" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:resolvable?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when resolved" do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.resolve!(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.unresolve!).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unsets resolved_at" do
|
|
|
|
subject.unresolve!
|
|
|
|
|
|
|
|
expect(subject.resolved_at).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unsets resolved_by" do
|
|
|
|
subject.unresolve!
|
|
|
|
|
|
|
|
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 not resolved" do
|
2017-09-05 13:51:08 -04:00
|
|
|
it "returns false" do
|
|
|
|
expect(subject.unresolve!).to be_falsey
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-05-22 06:24:14 -04:00
|
|
|
|
|
|
|
describe "#potentially_resolvable?" do
|
|
|
|
it 'returns false if noteable could not be found' do
|
|
|
|
allow(subject).to receive(:noteable).and_return(nil)
|
|
|
|
|
|
|
|
expect(subject.potentially_resolvable?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|