2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-24 13:11:48 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Banzai::IssuableExtractor do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-08-24 13:11:48 -04:00
|
|
|
let(:user) { create(:user) }
|
2018-04-03 09:45:17 -04:00
|
|
|
let(:extractor) { described_class.new(Banzai::RenderContext.new(project, user)) }
|
2016-08-24 13:11:48 -04:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
let(:issue_link) do
|
|
|
|
html_to_node(
|
|
|
|
"<a href='' data-issue='#{issue.id}' data-reference-type='issue' class='gfm'>text</a>"
|
|
|
|
)
|
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2016-08-24 13:11:48 -04:00
|
|
|
let(:merge_request_link) do
|
|
|
|
html_to_node(
|
|
|
|
"<a href='' data-merge-request='#{merge_request.id}' data-reference-type='merge_request' class='gfm'>text</a>"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def html_to_node(html)
|
|
|
|
Nokogiri::HTML.fragment(
|
|
|
|
html
|
|
|
|
).children[0]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns instances of issuables for nodes with references' do
|
|
|
|
result = extractor.extract([issue_link, merge_request_link])
|
|
|
|
|
|
|
|
expect(result).to eq(issue_link => issue, merge_request_link => merge_request)
|
|
|
|
end
|
|
|
|
|
2017-06-09 13:12:51 -04:00
|
|
|
describe 'caching', :request_store do
|
2016-08-24 13:11:48 -04:00
|
|
|
it 'saves records to cache' do
|
|
|
|
extractor.extract([issue_link, merge_request_link])
|
|
|
|
|
|
|
|
second_call_queries = ActiveRecord::QueryRecorder.new do
|
|
|
|
extractor.extract([issue_link, merge_request_link])
|
|
|
|
end.count
|
|
|
|
|
|
|
|
expect(second_call_queries).to eq 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|