Commit 03a9d014 authored by Sean McGivern's avatar Sean McGivern

Merge branch...

Merge branch '355481-empty-search-results-throw-error-undefined-method-eager_load-for-kaminari-paginatablearray' into 'master'

Fix search presenter raising exceptions from empty results

See merge request gitlab-org/gitlab!82619
parents ffb0b059 2b309e39
......@@ -25,7 +25,7 @@ class SearchServicePresenter < Gitlab::View::Presenter::Delegated
case scope
when 'users'
objects.eager_load(:status) # rubocop:disable CodeReuse/ActiveRecord
objects.eager_load(:status) if objects.respond_to?(:eager_load) # rubocop:disable CodeReuse/ActiveRecord
when 'commits'
prepare_commits_for_rendering(objects)
else
......
......@@ -4,13 +4,33 @@ require 'spec_helper'
RSpec.describe SearchServicePresenter do
let(:user) { create(:user) }
let(:search) { '' }
let(:search_service) { SearchService.new(user, search: search, scope: scope) }
let(:presenter) { described_class.new(search_service, current_user: user) }
describe '#search_objects' do
let(:search_objects) { Kaminari::PaginatableArray.new([]) }
context 'objects do not respond to eager_load' do
before do
allow(search_service).to receive(:search_objects).and_return(search_objects)
allow(search_objects).to receive(:respond_to?).with(:eager_load).and_return(false)
end
context 'users scope' do
let(:scope) { 'users' }
it 'does not eager load anything' do
expect(search_objects).not_to receive(:eager_load)
presenter.search_objects
end
end
end
end
describe '#show_results_status?' do
using RSpec::Parameterized::TableSyntax
let(:search) { '' }
let(:scope) { nil }
before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment