2019-11-07 22:06:48 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-12 03:16:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::FileFinder do
|
2017-05-12 03:16:33 -04:00
|
|
|
describe '#find' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2018-06-06 20:14:10 -04:00
|
|
|
subject { described_class.new(project, project.default_branch) }
|
2017-05-12 03:16:33 -04:00
|
|
|
|
2018-06-04 07:41:37 -04:00
|
|
|
it_behaves_like 'file finder' do
|
2019-10-23 20:07:18 -04:00
|
|
|
let(:expected_file_by_path) { 'files/images/wm.svg' }
|
2018-06-04 07:41:37 -04:00
|
|
|
let(:expected_file_by_content) { 'CHANGELOG' }
|
2017-05-12 03:16:33 -04:00
|
|
|
end
|
2018-06-06 20:14:10 -04:00
|
|
|
|
2020-08-17 14:10:01 -04:00
|
|
|
context 'with inclusive filters' do
|
|
|
|
it 'filters by filename' do
|
|
|
|
results = subject.find('files filename:wm.svg')
|
2018-06-06 20:14:10 -04:00
|
|
|
|
2020-08-17 14:10:01 -04:00
|
|
|
expect(results.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by path' do
|
|
|
|
results = subject.find('white path:images')
|
2018-06-06 20:14:10 -04:00
|
|
|
|
2020-08-17 14:10:01 -04:00
|
|
|
expect(results.count).to eq(1)
|
|
|
|
end
|
2018-06-06 20:14:10 -04:00
|
|
|
|
2020-08-17 14:10:01 -04:00
|
|
|
it 'filters by extension' do
|
|
|
|
results = subject.find('files extension:md')
|
|
|
|
|
|
|
|
expect(results.count).to eq(4)
|
|
|
|
end
|
2018-06-06 20:14:10 -04:00
|
|
|
end
|
|
|
|
|
2020-08-17 14:10:01 -04:00
|
|
|
context 'with exclusive filters' do
|
|
|
|
it 'filters by filename' do
|
|
|
|
results = subject.find('files -filename:wm.svg')
|
|
|
|
|
|
|
|
expect(results.count).to eq(26)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by path' do
|
|
|
|
results = subject.find('white -path:images')
|
|
|
|
|
|
|
|
expect(results.count).to eq(4)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by extension' do
|
|
|
|
results = subject.find('files -extension:md')
|
2018-06-06 20:14:10 -04:00
|
|
|
|
2020-08-17 14:10:01 -04:00
|
|
|
expect(results.count).to eq(23)
|
|
|
|
end
|
2018-06-06 20:14:10 -04:00
|
|
|
end
|
2020-01-03 07:07:59 -05:00
|
|
|
|
2021-02-01 04:09:28 -05:00
|
|
|
context 'with white space in the path' do
|
|
|
|
it 'filters by path correctly' do
|
|
|
|
results = subject.find('directory path:"with space/README.md"')
|
|
|
|
|
|
|
|
expect(results.count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-03 07:07:59 -05:00
|
|
|
it 'does not cause N+1 query' do
|
|
|
|
expect(Gitlab::GitalyClient).to receive(:call).at_most(10).times.and_call_original
|
|
|
|
|
|
|
|
subject.find(': filename:wm.svg')
|
|
|
|
end
|
2017-05-12 03:16:33 -04:00
|
|
|
end
|
|
|
|
end
|