Merge pull request #3002 from jmay/group-membership-api

use limit & offset for pagination of group members
This commit is contained in:
Sam 2014-12-03 11:11:10 +11:00
commit a8ff5fe97c
2 changed files with 20 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,20 @@ 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)) }
usernames = group.users.map{ |m| m['username'] }.sort
xhr :get, :members, group_id: group.name, limit: 3
response.should be_success
members = JSON.parse(response.body)
members.map{ |m| m['username'] }.should eq(usernames[0..2])
xhr :get, :members, group_id: group.name, limit: 3, offset: 3
response.should be_success
members = JSON.parse(response.body)
members.map{ |m| m['username'] }.should eq(usernames[3..4])
end
end
end