2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-01 12:01:09 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::SnippetSearchResults do
|
2019-09-09 09:46:24 -04:00
|
|
|
include SearchHelpers
|
|
|
|
|
2020-04-29 05:10:04 -04:00
|
|
|
let_it_be(:snippet) { create(:snippet, content: 'foo', file_name: 'foo') }
|
2019-09-30 11:08:09 -04:00
|
|
|
let(:results) { described_class.new(snippet.author, 'foo') }
|
2016-03-01 12:01:09 -05:00
|
|
|
|
|
|
|
describe '#snippet_titles_count' do
|
|
|
|
it 'returns the amount of matched snippet titles' do
|
2019-09-30 11:08:09 -04:00
|
|
|
expect(results.limited_snippet_titles_count).to eq(1)
|
2016-03-01 12:01:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-15 13:59:57 -04:00
|
|
|
describe '#formatted_count' do
|
2020-04-29 05:10:04 -04:00
|
|
|
it 'returns the expected formatted count' do
|
|
|
|
expect(results).to receive(:limited_snippet_titles_count).and_return(1234)
|
|
|
|
expect(results.formatted_count('snippet_titles')).to eq(max_limited_count)
|
2019-07-15 13:59:57 -04:00
|
|
|
end
|
|
|
|
end
|
2020-05-07 17:09:26 -04:00
|
|
|
|
|
|
|
describe '#objects' do
|
|
|
|
it 'uses page and per_page to paginate results' do
|
|
|
|
snippet2 = create(:snippet, :public, content: 'foo', file_name: 'foo')
|
|
|
|
|
|
|
|
expect(results.objects('snippet_titles', page: 1, per_page: 1).to_a).to eq([snippet2])
|
|
|
|
expect(results.objects('snippet_titles', page: 2, per_page: 1).to_a).to eq([snippet])
|
|
|
|
expect(results.objects('snippet_titles', page: 1, per_page: 2).count).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
2016-03-01 12:01:09 -05:00
|
|
|
end
|