use limit & offset for pagination of group members

This commit is contained in:
Jason W. May 2014-11-24 12:12:48 -08:00
parent d3510bff04
commit adb570fe53
2 changed files with 19 additions and 2 deletions

View File

@ -18,8 +18,11 @@ class GroupsController < ApplicationController
def members
group = find_group(:group_id)
members = group.users.order('username_lower asc')
members = members.limit(200) if group.automatic
limit = (params[:limit] || 200).to_i
offset = (params[:offset] || 0).to_i
members = group.users.order('username_lower asc').limit(limit).offset(offset)
render_serialized(members.to_a, GroupUserSerializer)
end

View File

@ -67,5 +67,19 @@ describe GroupsController do
xhr :get, :posts, group_id: group.name
response.should be_success
end
it "ensures that membership can be paginated" do
5.times { group.add(Fabricate(:user)) }
xhr :get, :members, group_id: group.name, limit: 3
response.should be_success
members = JSON.parse(response.body)
members.count.should eq(3)
xhr :get, :members, group_id: group.name, limit: 250, offset: 250
xhr :get, :members, group_id: group.name, limit: 3, offset: 3
response.should be_success
members = JSON.parse(response.body)
members.count.should eq(2)
end
end
end