2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Banzai::IssuableExtractor do
|
|
|
|
let(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:extractor) { described_class.new(project, user) }
|
|
|
|
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
|
|
|
|
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-09-10 17:25:29 +05:30
|
|
|
describe 'caching', :request_store do
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|