Commit f48642e2 authored by Douwe Maan's avatar Douwe Maan

Add specs for Discussion and MergeRequest models

parent 33edde50
...@@ -83,9 +83,7 @@ class Discussion ...@@ -83,9 +83,7 @@ class Discussion
end end
def to_be_resolved? def to_be_resolved?
return @to_be_resolved if defined?(@to_be_resolved) resolvable? && !resolved?
@to_be_resolved = notes.any?(&:to_be_resolved?)
end end
def can_resolve?(current_user) def can_resolve?(current_user)
...@@ -97,12 +95,16 @@ class Discussion ...@@ -97,12 +95,16 @@ class Discussion
end end
def resolve!(current_user) def resolve!(current_user)
return unless resolvable?
notes.each do |note| notes.each do |note|
note.resolve!(current_user) if note.resolvable? note.resolve!(current_user) if note.resolvable?
end end
end end
def unresolve! def unresolve!
return unless resolvable?
notes.each do |note| notes.each do |note|
note.unresolve! if note.resolvable? note.unresolve! if note.resolvable?
end end
......
This diff is collapsed.
...@@ -741,4 +741,96 @@ describe MergeRequest, models: true do ...@@ -741,4 +741,96 @@ describe MergeRequest, models: true do
end end
end end
end end
context "discussion status" do
let(:first_discussion) { Discussion.new([create(:diff_note_on_merge_request)]) }
let(:second_discussion) { Discussion.new([create(:diff_note_on_merge_request)]) }
let(:third_discussion) { Discussion.new([create(:diff_note_on_merge_request)]) }
before do
allow(subject).to receive(:discussions).and_return([first_discussion, second_discussion, third_discussion])
end
describe "#discussions_resolvable?" do
context "when all discussions are unresolvable" do
before do
allow(first_discussion).to receive(:resolvable?).and_return(false)
allow(second_discussion).to receive(:resolvable?).and_return(false)
allow(third_discussion).to receive(:resolvable?).and_return(false)
end
it "returns false" do
expect(subject.discussions_resolvable?).to be false
end
end
context "when some discussions are unresolvable and some discussions are resolvable" do
before do
allow(first_discussion).to receive(:resolvable?).and_return(true)
allow(second_discussion).to receive(:resolvable?).and_return(false)
allow(third_discussion).to receive(:resolvable?).and_return(true)
end
it "returns true" do
expect(subject.discussions_resolvable?).to be true
end
end
context "when all discussions are resolvable" do
before do
allow(first_discussion).to receive(:resolvable?).and_return(true)
allow(second_discussion).to receive(:resolvable?).and_return(true)
allow(third_discussion).to receive(:resolvable?).and_return(true)
end
it "returns true" do
expect(subject.discussions_resolvable?).to be true
end
end
end
describe "#discussions_resolved?" do
context "when discussions are not resolvable" do
before do
allow(subject).to receive(:discussions_resolvable?).and_return(false)
end
it "returns false" do
expect(subject.discussions_resolved?).to be false
end
end
context "when discussions are resolvable" do
before do
allow(subject).to receive(:discussions_resolvable?).and_return(true)
allow(first_discussion).to receive(:resolvable?).and_return(true)
allow(second_discussion).to receive(:resolvable?).and_return(false)
allow(third_discussion).to receive(:resolvable?).and_return(true)
end
context "when all resolvable discussions are resolved" do
before do
allow(first_discussion).to receive(:resolved?).and_return(true)
allow(third_discussion).to receive(:resolved?).and_return(true)
end
it "returns true" do
expect(subject.discussions_resolved?).to be true
end
end
context "when some resolvable discussions are not resolved" do
before do
allow(first_discussion).to receive(:resolved?).and_return(true)
allow(third_discussion).to receive(:resolved?).and_return(false)
end
it "returns false" do
expect(subject.discussions_resolved?).to be false
end
end
end
end
end
end end
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