file_finder_spec.rb 973 Bytes
Newer Older
1 2
# frozen_string_literal: true

Valery Sizov's avatar
Valery Sizov committed
3 4
require 'spec_helper'

5
describe Gitlab::FileFinder do
Valery Sizov's avatar
Valery Sizov committed
6 7
  describe '#find' do
    let(:project) { create(:project, :public, :repository) }
8

9
    subject { described_class.new(project, project.default_branch) }
Valery Sizov's avatar
Valery Sizov committed
10

11
    it_behaves_like 'file finder' do
12
      let(:expected_file_by_path) { 'files/images/wm.svg' }
13
      let(:expected_file_by_content) { 'CHANGELOG' }
Valery Sizov's avatar
Valery Sizov committed
14
    end
15

16
    it 'filters by filename' do
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
      results = subject.find('files filename:wm.svg')

      expect(results.count).to eq(1)
    end

    it 'filters by path' do
      results = subject.find('white path:images')

      expect(results.count).to eq(1)
    end

    it 'filters by extension' do
      results = subject.find('files extension:svg')

      expect(results.count).to eq(1)
    end
33 34 35 36 37 38

    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
Valery Sizov's avatar
Valery Sizov committed
39 40
  end
end