debian-mirror-gitlab/spec/lib/banzai/filter/abstract_reference_filter_spec.rb

95 lines
3 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe Banzai::Filter::AbstractReferenceFilter do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
describe '#references_per_parent' do
it 'returns a Hash containing references grouped per parent paths' do
2017-09-10 17:25:29 +05:30
doc = Nokogiri::HTML.fragment("#1 #{project.full_path}#2")
2017-08-17 22:00:37 +05:30
filter = described_class.new(doc, project: project)
expect(filter).to receive(:object_class).exactly(4).times.and_return(Issue)
expect(filter).to receive(:object_sym).twice.and_return(:issue)
2018-03-17 18:26:18 +05:30
refs = filter.references_per_parent
2017-08-17 22:00:37 +05:30
expect(refs).to be_an_instance_of(Hash)
2017-09-10 17:25:29 +05:30
expect(refs[project.full_path]).to eq(Set.new(%w[1 2]))
2017-08-17 22:00:37 +05:30
end
end
2018-03-17 18:26:18 +05:30
describe '#parent_per_reference' do
it 'returns a Hash containing projects grouped per parent paths' do
2017-08-17 22:00:37 +05:30
doc = Nokogiri::HTML.fragment('')
filter = described_class.new(doc, project: project)
2018-03-17 18:26:18 +05:30
expect(filter).to receive(:references_per_parent)
2017-09-10 17:25:29 +05:30
.and_return({ project.full_path => Set.new(%w[1]) })
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(filter.parent_per_reference)
2017-09-10 17:25:29 +05:30
.to eq({ project.full_path => project })
2017-08-17 22:00:37 +05:30
end
end
2018-03-17 18:26:18 +05:30
describe '#find_for_paths' do
2017-08-17 22:00:37 +05:30
let(:doc) { Nokogiri::HTML.fragment('') }
let(:filter) { described_class.new(doc, project: project) }
context 'with RequestStore disabled' do
it 'returns a list of Projects for a list of paths' do
2018-03-17 18:26:18 +05:30
expect(filter.find_for_paths([project.full_path]))
2017-09-10 17:25:29 +05:30
.to eq([project])
2017-08-17 22:00:37 +05:30
end
it "return an empty array for paths that don't exist" do
2018-03-17 18:26:18 +05:30
expect(filter.find_for_paths(['nonexistent/project']))
2017-09-10 17:25:29 +05:30
.to eq([])
2017-08-17 22:00:37 +05:30
end
end
2017-09-10 17:25:29 +05:30
context 'with RequestStore enabled', :request_store do
2017-08-17 22:00:37 +05:30
it 'returns a list of Projects for a list of paths' do
2018-03-17 18:26:18 +05:30
expect(filter.find_for_paths([project.full_path]))
2017-09-10 17:25:29 +05:30
.to eq([project])
2017-08-17 22:00:37 +05:30
end
context "when no project with that path exists" do
it "returns no value" do
2018-03-17 18:26:18 +05:30
expect(filter.find_for_paths(['nonexistent/project']))
2017-09-10 17:25:29 +05:30
.to eq([])
2017-08-17 22:00:37 +05:30
end
it "adds the ref to the project refs cache" do
project_refs_cache = {}
2018-03-17 18:26:18 +05:30
allow(filter).to receive(:refs_cache).and_return(project_refs_cache)
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
filter.find_for_paths(['nonexistent/project'])
2017-08-17 22:00:37 +05:30
expect(project_refs_cache).to eq({ 'nonexistent/project' => nil })
end
context 'when the project refs cache includes nil values' do
before do
# adds { 'nonexistent/project' => nil } to cache
2018-03-17 18:26:18 +05:30
filter.from_ref_cached('nonexistent/project')
2017-08-17 22:00:37 +05:30
end
it "return an empty array for paths that don't exist" do
2018-03-17 18:26:18 +05:30
expect(filter.find_for_paths(['nonexistent/project']))
2017-09-10 17:25:29 +05:30
.to eq([])
2017-08-17 22:00:37 +05:30
end
end
end
end
end
2018-03-17 18:26:18 +05:30
describe '#current_parent_path' do
it 'returns the path of the current parent' do
2017-08-17 22:00:37 +05:30
doc = Nokogiri::HTML.fragment('')
filter = described_class.new(doc, project: project)
2018-03-17 18:26:18 +05:30
expect(filter.current_parent_path).to eq(project.full_path)
2017-08-17 22:00:37 +05:30
end
end
end