Commit b26cd5aa authored by Stan Hu's avatar Stan Hu

Merge branch '34420-optimize-pagination-on-explore-snippets' into 'master'

Explore snippets page show only next/previous page links

See merge request gitlab-org/gitlab!25404
parents b8494c07 60f68b71
# frozen_string_literal: true
class Explore::SnippetsController < Explore::ApplicationController
include PaginatedCollection
include Gitlab::NoteableMetadata
def index
@snippets = SnippetsFinder.new(current_user, explore: true)
.execute
.page(params[:page])
.without_count
.inc_author
return if redirect_out_of_range(@snippets)
@noteable_meta_data = noteable_meta_data(@snippets, 'Snippet')
end
end
......@@ -8,4 +8,4 @@
%ul.content-list
= render partial: 'shared/snippets/snippet', collection: @snippets, locals: { link_project: link_project }
= paginate @snippets, theme: 'gitlab', remote: remote
= paginate_collection @snippets, remote: remote
---
title: Showing only "Next" button for snippet explore page.
merge_request: 25404
author:
type: changed
......@@ -4,12 +4,33 @@ require 'spec_helper'
describe Explore::SnippetsController do
describe 'GET #index' do
it_behaves_like 'paginated collection' do
let(:collection) { Snippet.all }
let!(:project_snippet) { create_list(:project_snippet, 3, :public) }
let!(:personal_snippet) { create_list(:personal_snippet, 3, :public) }
before do
create(:personal_snippet, :public)
allow(Kaminari.config).to receive(:default_per_page).and_return(2)
end
it 'renders' do
get :index
snippets = assigns(:snippets)
expect(snippets).to be_a(::Kaminari::PaginatableWithoutCount)
expect(snippets.size).to eq(2)
expect(snippets).to all(be_a(PersonalSnippet))
expect(response).to have_gitlab_http_status(:ok)
end
it 'renders pagination' do
get :index, params: { page: 2 }
snippets = assigns(:snippets)
expect(snippets).to be_a(::Kaminari::PaginatableWithoutCount)
expect(snippets.size).to eq(1)
expect(assigns(:snippets)).to all(be_a(PersonalSnippet))
expect(response).to have_gitlab_http_status(:ok)
end
end
end
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