Commit 72d730b3 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch '26952-fix-viewing-legacy-diff-notes-in-discussion' into 'master'

Fix viewing some legacy diff notes in discussions

See merge request gitlab-org/gitlab!45920
parents faf565d3 d7796005
...@@ -10,5 +10,13 @@ module DiffViewer ...@@ -10,5 +10,13 @@ module DiffViewer
self.binary = true self.binary = true
self.switcher_icon = 'doc-image' self.switcher_icon = 'doc-image'
self.switcher_title = _('image diff') self.switcher_title = _('image diff')
def self.can_render?(diff_file, verify_binary: true)
# When both blobs are missing, we often still have a textual diff that can
# be displayed
return false if diff_file.old_blob.nil? && diff_file.new_blob.nil?
super
end
end end
end end
---
title: Fix viewing GitHub-imported diff notes in discussions
merge_request: 45920
author:
type: fixed
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe DiffViewer::Image do
describe '.can_render?' do
let(:diff_file) { double(Gitlab::Diff::File) }
let(:blob) { double(Gitlab::Git::Blob, binary_in_repo?: true, extension: 'png') }
subject { described_class.can_render?(diff_file, verify_binary: false) }
it 'returns false if both old and new blob are absent' do
allow(diff_file).to receive(:old_blob) { nil }
allow(diff_file).to receive(:new_blob) { nil }
is_expected.to be_falsy
end
it 'returns true if the old blob is present' do
allow(diff_file).to receive(:old_blob) { blob }
allow(diff_file).to receive(:new_blob) { nil }
is_expected.to be_truthy
end
it 'returns true if the new blob is present' do
allow(diff_file).to receive(:old_blob) { nil }
allow(diff_file).to receive(:new_blob) { blob }
is_expected.to be_truthy
end
it 'returns true if both old and new blobs are present' do
allow(diff_file).to receive(:old_blob) { blob }
allow(diff_file).to receive(:new_blob) { blob }
is_expected.to be_truthy
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