debian-mirror-gitlab/spec/lib/banzai/issuable_extractor_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.6 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Banzai::IssuableExtractor, feature_category: :team_planning do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
let(:user) { create(:user) }
2018-05-09 12:01:36 +05:30
let(:extractor) { described_class.new(Banzai::RenderContext.new(project, user)) }
2017-08-17 22:00:37 +05:30
let(:issue) { create(:issue, project: project) }
2023-07-09 08:55:56 +05:30
let(:work_item) { create(:work_item, project: project) }
2017-08-17 22:00:37 +05:30
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-10-24 23:57:45 +05:30
2023-07-09 08:55:56 +05:30
let(:work_item_link) do
html_to_node(
"<a href='' data-work-item='#{work_item.id}' data-reference-type='work_item' class='gfm'>text</a>"
)
end
2017-08-17 22:00:37 +05:30
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
2023-07-09 08:55:56 +05:30
result = extractor.extract([issue_link, work_item_link, merge_request_link])
2017-08-17 22:00:37 +05:30
2023-07-09 08:55:56 +05:30
expect(result).to eq(issue_link => issue, work_item_link => work_item, merge_request_link => merge_request)
2017-08-17 22:00:37 +05:30
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
2023-07-09 08:55:56 +05:30
extractor.extract([issue_link, work_item_link, merge_request_link])
2017-08-17 22:00:37 +05:30
second_call_queries = ActiveRecord::QueryRecorder.new do
2023-07-09 08:55:56 +05:30
extractor.extract([issue_link, work_item_link, merge_request_link])
2017-08-17 22:00:37 +05:30
end.count
expect(second_call_queries).to eq 0
end
end
end