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