mirror of
https://github.com/discourse/discourse.git
synced 2025-03-23 18:40:38 +08:00
FIX: groups pagination was broken
This commit is contained in:
parent
0c4ac2a7bc
commit
7b83237261
@ -80,6 +80,9 @@ class GroupsController < ApplicationController
|
||||
type_filters = type_filters - [:my, :owner]
|
||||
end
|
||||
|
||||
# count the total before doing pagination
|
||||
total = groups.count
|
||||
|
||||
page = params[:page].to_i
|
||||
page_size = MobileDetection.mobile_device?(request.user_agent) ? 15 : 36
|
||||
groups = groups.offset(page * page_size).limit(page_size)
|
||||
@ -93,14 +96,14 @@ class GroupsController < ApplicationController
|
||||
extras: {
|
||||
type_filters: type_filters
|
||||
},
|
||||
total_rows_groups: groups.count,
|
||||
total_rows_groups: total,
|
||||
load_more_groups: groups_path(
|
||||
page: page + 1,
|
||||
type: type,
|
||||
order: order,
|
||||
asc: params[:asc],
|
||||
filter: filter
|
||||
),
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -14,6 +14,30 @@ describe GroupsController do
|
||||
Fabricate(:group, name: 'staff_group', visibility_level: Group.visibility_levels[:staff])
|
||||
end
|
||||
|
||||
it "ensures that groups can be paginated" do
|
||||
50.times { Fabricate(:group) }
|
||||
|
||||
get "/groups.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
|
||||
expect(body["groups"].size).to eq(36)
|
||||
expect(body["total_rows_groups"]).to eq(50)
|
||||
expect(body["load_more_groups"]).to eq("/groups?page=1")
|
||||
|
||||
get "/groups.json", params: { page: 1 }
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
|
||||
expect(body["groups"].size).to eq(14)
|
||||
expect(body["total_rows_groups"]).to eq(50)
|
||||
expect(body["load_more_groups"]).to eq("/groups?page=2")
|
||||
end
|
||||
|
||||
context 'when group directory is disabled' do
|
||||
before do
|
||||
SiteSetting.enable_group_directory = false
|
||||
|
Loading…
x
Reference in New Issue
Block a user