2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::FileFinder do
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '#find' do
|
|
|
|
let(: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
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context 'with inclusive filters' do
|
|
|
|
it 'filters by filename' do
|
|
|
|
results = subject.find('files filename:wm.svg')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(results.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by path' do
|
|
|
|
results = subject.find('white path:images')
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(results.count).to eq(1)
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it 'filters by extension' do
|
|
|
|
results = subject.find('files extension:md')
|
|
|
|
|
|
|
|
expect(results.count).to eq(4)
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
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')
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(results.count).to eq(23)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
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-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|