Allow truncated_diff_lines to be called on image diff discussion

This commit is contained in:
Douwe Maan 2018-12-20 15:24:25 +01:00
parent f6dd6e566a
commit 047b7e506e
No known key found for this signature in database
GPG Key ID: 5976703F65143D36
2 changed files with 9 additions and 2 deletions

View File

@ -39,6 +39,7 @@ module DiscussionOnDiff
# Returns an array of at most 16 highlighted lines above a diff note
def truncated_diff_lines(highlight: true, diff_limit: nil)
return [] unless on_text?
return [] if diff_line.nil? && first_note.is_a?(LegacyDiffNote)
diff_limit = [diff_limit, NUMBER_OF_TRUNCATED_DIFF_LINES].compact.min

View File

@ -50,11 +50,17 @@ describe DiscussionOnDiff do
end
context "when the diff line does not exist on a legacy diff note" do
subject { create(:legacy_diff_note_on_merge_request).to_discussion }
it "returns an empty array" do
legacy_note = LegacyDiffNote.new
expect(truncated_lines).to eq([])
end
end
allow(subject).to receive(:first_note).and_return(legacy_note)
context 'when the discussion is on an image' do
subject { create(:image_diff_note_on_merge_request).to_discussion }
it 'returns an empty array' do
expect(truncated_lines).to eq([])
end
end