debian-mirror-gitlab/spec/lib/gitlab/file_finder_spec.rb

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

71 lines
1.7 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Gitlab::FileFinder, feature_category: :global_search do
2017-09-10 17:25:29 +05:30
describe '#find' do
2023-04-23 21:23:45 +05:30
let_it_be(:project) { create(:project, :public, :repository) }
2020-01-01 13:55:28 +05:30
2018-11-08 19:23:39 +05:30
subject { described_class.new(project, project.default_branch) }
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
it_behaves_like 'file finder' do
2019-12-26 22:10:19 +05:30
let(:expected_file_by_path) { 'files/images/wm.svg' }
2018-11-08 19:23:39 +05:30
let(:expected_file_by_content) { 'CHANGELOG' }
end
2023-05-27 22:25:52 +05:30
context 'with inclusive filters' do
it 'filters by filename' do
results = subject.find('files filename:wm.svg')
2023-04-23 21:23:45 +05:30
2023-05-27 22:25:52 +05:30
expect(results.count).to eq(1)
2020-10-24 23:57:45 +05:30
end
2018-11-08 19:23:39 +05:30
2023-05-27 22:25:52 +05:30
it 'filters by path' do
results = subject.find('white path:images')
2020-10-24 23:57:45 +05:30
2023-05-27 22:25:52 +05:30
expect(results.count).to eq(2)
2020-10-24 23:57:45 +05:30
end
2017-09-10 17:25:29 +05:30
2023-05-27 22:25:52 +05:30
it 'filters by extension' do
results = subject.find('files extension:md')
2020-10-24 23:57:45 +05:30
2023-05-27 22:25:52 +05:30
expect(results.count).to eq(4)
2020-10-24 23:57:45 +05:30
end
2023-04-23 21:23:45 +05:30
end
2020-10-24 23:57:45 +05:30
2023-05-27 22:25:52 +05:30
context 'with exclusive filters' do
it 'filters by filename' do
results = subject.find('files -filename:wm.svg')
2023-04-23 21:23:45 +05:30
2023-05-27 22:25:52 +05:30
expect(results.count).to eq(26)
2020-10-24 23:57:45 +05:30
end
2023-05-27 22:25:52 +05:30
it 'filters by path' do
results = subject.find('white -path:images')
2023-04-23 21:23:45 +05:30
2023-05-27 22:25:52 +05:30
expect(results.count).to eq(5)
end
2023-04-23 21:23:45 +05:30
2023-05-27 22:25:52 +05:30
it 'filters by extension' do
results = subject.find('files -extension:md')
2023-04-23 21:23:45 +05:30
2023-05-27 22:25:52 +05:30
expect(results.count).to eq(23)
2020-10-24 23:57:45 +05:30
end
2023-05-27 22:25:52 +05:30
end
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
context 'with white space in the path' do
it 'filters by path correctly' do
results = subject.find('directory path:"with space/README.md"')
2021-03-11 19:13:27 +05:30
2023-05-27 22:25:52 +05:30
expect(results.count).to eq(1)
2021-03-11 19:13:27 +05:30
end
2023-05-27 22:25:52 +05:30
end
2021-03-11 19:13:27 +05:30
2023-05-27 22:25:52 +05:30
it 'does not cause N+1 query' do
expect(Gitlab::GitalyClient).to receive(:call).at_most(10).times.and_call_original
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
subject.find(': filename:wm.svg')
2020-03-13 15:44:24 +05:30
end
2017-09-10 17:25:29 +05:30
end
end