summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/diff/highlight_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 15:44:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 15:44:42 +0000
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /spec/lib/gitlab/diff/highlight_spec.rb
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
downloadgitlab-ce-4555e1b21c365ed8303ffb7a3325d773c9b8bf31.tar.gz
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/lib/gitlab/diff/highlight_spec.rb')
-rw-r--r--spec/lib/gitlab/diff/highlight_spec.rb32
1 files changed, 31 insertions, 1 deletions
diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb
index 32ca6e4fde6..94d3b2ad0b3 100644
--- a/spec/lib/gitlab/diff/highlight_spec.rb
+++ b/spec/lib/gitlab/diff/highlight_spec.rb
@@ -5,7 +5,8 @@ require 'spec_helper'
RSpec.describe Gitlab::Diff::Highlight do
include RepoHelpers
- let(:project) { create(:project, :repository) }
+ let_it_be(:project) { create(:project, :repository) }
+
let(:commit) { project.commit(sample_commit.id) }
let(:diff) { commit.raw_diffs.first }
let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: commit.diff_refs, repository: project.repository) }
@@ -156,5 +157,34 @@ RSpec.describe Gitlab::Diff::Highlight do
it_behaves_like 'without inline diffs'
end
end
+
+ context 'when blob is too large' do
+ let(:subject) { described_class.new(diff_file, repository: project.repository).highlight }
+
+ before do
+ allow(Gitlab::Highlight).to receive(:too_large?).and_return(true)
+ end
+
+ it 'blobs are highlighted as plain text without loading all data' do
+ expect(diff_file.blob).not_to receive(:load_all_data!)
+
+ expect(subject[2].rich_text).to eq(%Q{ <span id="LC7" class="line" lang=""> def popen(cmd, path=nil)</span>\n})
+ expect(subject[2].rich_text).to be_html_safe
+ end
+
+ context 'when limited_diff_highlighting is disabled' do
+ before do
+ stub_feature_flags(limited_diff_highlighting: false)
+ stub_feature_flags(diff_line_syntax_highlighting: false)
+ end
+
+ it 'blobs are highlighted as plain text with loading all data' do
+ expect(diff_file.blob).to receive(:load_all_data!).twice
+
+ code = %Q{ <span id="LC7" class="line" lang=""> def popen(cmd, path=nil)</span>\n}
+ expect(subject[2].rich_text).to eq(code)
+ end
+ end
+ end
end
end