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

34 lines
1.1 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::SnippetSearchResults do
2019-12-04 20:38:33 +05:30
include SearchHelpers
2020-05-24 23:13:21 +05:30
let_it_be(:snippet) { create(:snippet, content: 'foo', file_name: 'foo') }
2019-12-21 20:55:43 +05:30
let(:results) { described_class.new(snippet.author, 'foo') }
2016-06-02 11:05:42 +05:30
describe '#snippet_titles_count' do
it 'returns the amount of matched snippet titles' do
2019-12-21 20:55:43 +05:30
expect(results.limited_snippet_titles_count).to eq(1)
2016-06-02 11:05:42 +05:30
end
end
2020-05-24 23:13:21 +05:30
describe '#formatted_count' do
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)
2016-06-02 11:05:42 +05:30
end
end
2019-10-12 21:52:04 +05:30
2020-05-24 23:13:21 +05:30
describe '#objects' do
it 'uses page and per_page to paginate results' do
snippet2 = create(:snippet, :public, content: 'foo', file_name: 'foo')
2019-10-12 21:52:04 +05:30
2020-05-24 23:13:21 +05:30
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)
2019-10-12 21:52:04 +05:30
end
end
2016-06-02 11:05:42 +05:30
end