summaryrefslogtreecommitdiff
path: root/spec/models/note_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r--spec/models/note_spec.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 328d3ba7dda..4b574540500 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -1622,6 +1622,50 @@ RSpec.describe Note do
expect(described_class.with_suggestions).not_to include(note_without_suggestion)
end
end
+
+ describe '.inc_relations_for_view' do
+ subject { note.noteable.notes.inc_relations_for_view(noteable) }
+
+ context 'when noteable can not have diffs' do
+ let_it_be(:note) { create(:note_on_issue) }
+ let(:noteable) { note.noteable }
+
+ it 'does not include additional associations' do
+ expect { subject.reload }.to match_query_count(0).for_model(NoteDiffFile).and(
+ match_query_count(0).for_model(DiffNotePosition))
+ end
+
+ context 'when noteable is not set' do
+ let(:noteable) { nil }
+
+ it 'includes additional diff associations' do
+ expect { subject.reload }.to match_query_count(1).for_model(NoteDiffFile).and(
+ match_query_count(1).for_model(DiffNotePosition))
+ end
+ end
+
+ context 'when skip_notes_diff_include flag is disabled' do
+ before do
+ stub_feature_flags(skip_notes_diff_include: false)
+ end
+
+ it 'includes additional diff associations' do
+ expect { subject.reload }.to match_query_count(1).for_model(NoteDiffFile).and(
+ match_query_count(1).for_model(DiffNotePosition))
+ end
+ end
+ end
+
+ context 'when noteable can have diffs' do
+ let_it_be(:note) { create(:note_on_commit) }
+ let(:noteable) { note.noteable }
+
+ it 'includes additional diff associations' do
+ expect { subject.reload }.to match_query_count(1).for_model(NoteDiffFile).and(
+ match_query_count(1).for_model(DiffNotePosition))
+ end
+ end
+ end
end
describe 'banzai_render_context' do