2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Banzai::Pipeline::PostProcessPipeline do
|
2021-06-08 01:23:25 +05:30
|
|
|
subject { described_class.call(doc, context) }
|
|
|
|
|
|
|
|
let_it_be(:project) { create(:project, :public, :repository) }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:context) { { project: project, ref: 'master' } }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
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
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'does not make any Gitaly calls', :request_store do
|
2020-03-13 15:44:24 +05:30
|
|
|
Gitlab::GitalyClient.reset_counts
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
subject
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
expect(Gitlab::GitalyClient.get_request_count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
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) }
|
|
|
|
let(:non_related_xpath_calls) { 2 }
|
|
|
|
|
|
|
|
it 'searches for attributes only once' do
|
|
|
|
expect(doc).to receive(:xpath).exactly(non_related_xpath_calls + 1).times
|
|
|
|
.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(:xpath).exactly(non_related_xpath_calls + 2).times
|
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|