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

41 lines
973 B
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'
describe Gitlab::FileFinder do
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
2019-12-26 22:10:19 +05:30
it 'filters by filename' do
2018-11-08 19:23:39 +05:30
results = subject.find('files filename:wm.svg')
2018-03-17 18:26:18 +05:30
2018-11-08 19:23:39 +05:30
expect(results.count).to eq(1)
2017-09-10 17:25:29 +05:30
end
2018-11-08 19:23:39 +05:30
it 'filters by path' do
results = subject.find('white path:images')
expect(results.count).to eq(1)
end
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
it 'filters by extension' do
results = subject.find('files extension:svg')
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
expect(results.count).to eq(1)
2017-09-10 17:25:29 +05:30
end
2020-03-09 13:42:32 +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