diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-23 12:10:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-23 12:10:03 +0300 |
commit | 65f7976d0cd11d91a4c0945b2c63a1aa2f888b07 (patch) | |
tree | 07a0e774b12b29352ca6b3bd87b108879ebb00b9 /spec/lib/banzai/pipeline/post_process_pipeline_spec.rb | |
parent | 1165608bfd217a96e133487d6049a989a15789c4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/banzai/pipeline/post_process_pipeline_spec.rb')
-rw-r--r-- | spec/lib/banzai/pipeline/post_process_pipeline_spec.rb | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/spec/lib/banzai/pipeline/post_process_pipeline_spec.rb b/spec/lib/banzai/pipeline/post_process_pipeline_spec.rb index d9f45769550..ebe1ca4d403 100644 --- a/spec/lib/banzai/pipeline/post_process_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/post_process_pipeline_spec.rb @@ -3,24 +3,56 @@ require 'spec_helper' RSpec.describe Banzai::Pipeline::PostProcessPipeline do - context 'when a document only has upload links' do - it 'does not make any Gitaly calls', :request_store do - markdown = <<-MARKDOWN.strip_heredoc - [Relative Upload Link](/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg) + subject { described_class.call(doc, context) } + + let_it_be(:project) { create(:project, :public, :repository) } - ![Relative Upload Image](/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg) - MARKDOWN + let(:context) { { project: project, ref: 'master' } } - context = { - project: create(:project, :public, :repository), - ref: 'master' - } + context 'when a document only has upload links' do + let(:doc) do + <<-HTML.strip_heredoc + <a href="/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg">Relative Upload Link</a> + <img src="/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"> + HTML + end + it 'does not make any Gitaly calls', :request_store do Gitlab::GitalyClient.reset_counts - described_class.call(markdown, context) + subject expect(Gitlab::GitalyClient.get_request_count).to eq(0) end end + + context 'when both upload and repository links are present' do + let(:html) do + <<-HTML.strip_heredoc + <a href="/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg">Relative Upload Link</a> + <img src="/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"> + <a href="/test.jpg">Just a link</a> + HTML + end + + let(:doc) { HTML::Pipeline.parse(html) } + + it 'searches for attributes only once' do + expect(doc).to receive(:search).once.and_call_original + + subject + end + + context 'when "optimize_linkable_attributes" is disabled' do + before do + stub_feature_flags(optimize_linkable_attributes: false) + end + + it 'searches for attributes twice' do + expect(doc).to receive(:search).twice.and_call_original + + subject + end + end + end end |