Commit 2b309e39 authored by John Mason's avatar John Mason Committed by Sean McGivern

Search presenter is a noop when given empty results

Changelog: changed
parent f480be75
...@@ -25,7 +25,7 @@ class SearchServicePresenter < Gitlab::View::Presenter::Delegated ...@@ -25,7 +25,7 @@ class SearchServicePresenter < Gitlab::View::Presenter::Delegated
case scope case scope
when 'users' 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' when 'commits'
prepare_commits_for_rendering(objects) prepare_commits_for_rendering(objects)
else else
......
...@@ -4,13 +4,33 @@ require 'spec_helper' ...@@ -4,13 +4,33 @@ require 'spec_helper'
RSpec.describe SearchServicePresenter do RSpec.describe SearchServicePresenter do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:search) { '' }
let(:search_service) { SearchService.new(user, search: search, scope: scope) } let(:search_service) { SearchService.new(user, search: search, scope: scope) }
let(:presenter) { described_class.new(search_service, current_user: user) } 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 describe '#show_results_status?' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
let(:search) { '' }
let(:scope) { nil } let(:scope) { nil }
before do 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