summaryrefslogtreecommitdiff
path: root/spec/models/concerns/noteable_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/concerns/noteable_spec.rb')
-rw-r--r--spec/models/concerns/noteable_spec.rb42
1 files changed, 41 insertions, 1 deletions
diff --git a/spec/models/concerns/noteable_spec.rb b/spec/models/concerns/noteable_spec.rb
index 5c8c5425ca7..bb7374bf46c 100644
--- a/spec/models/concerns/noteable_spec.rb
+++ b/spec/models/concerns/noteable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Noteable do
+RSpec.describe Noteable do
let!(:active_diff_note1) { create(:diff_note_on_merge_request) }
let(:project) { active_diff_note1.project }
subject { active_diff_note1.noteable }
@@ -262,4 +262,44 @@ describe Noteable do
end
end
end
+
+ describe "#has_any_diff_note_positions?" do
+ let(:source_branch) { "compare-with-merge-head-source" }
+ let(:target_branch) { "compare-with-merge-head-target" }
+ let(:merge_request) { create(:merge_request, source_branch: source_branch, target_branch: target_branch) }
+
+ let!(:note) do
+ path = "files/markdown/ruby-style-guide.md"
+
+ position = Gitlab::Diff::Position.new(
+ old_path: path,
+ new_path: path,
+ new_line: 508,
+ diff_refs: merge_request.diff_refs
+ )
+
+ create(:diff_note_on_merge_request, project: merge_request.project, position: position, noteable: merge_request)
+ end
+
+ before do
+ MergeRequests::MergeToRefService.new(merge_request.project, merge_request.author).execute(merge_request)
+ Discussions::CaptureDiffNotePositionsService.new(merge_request).execute
+ end
+
+ it "returns true when it has diff note positions" do
+ expect(merge_request.has_any_diff_note_positions?).to be(true)
+ end
+
+ it "returns false when it has notes but no diff note positions" do
+ DiffNotePosition.where(note: note).find_each(&:delete)
+
+ expect(merge_request.has_any_diff_note_positions?).to be(false)
+ end
+
+ it "returns false when it has no notes" do
+ merge_request.notes.find_each(&:destroy)
+
+ expect(merge_request.has_any_diff_note_positions?).to be(false)
+ end
+ end
end