diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index dd1feec96..a687cded1 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -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 diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index bbaa136d2..63ac27d4b 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -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