FIX: Incorrect count when loading more groups.

This commit is contained in:
Guo Xiang Tan 2016-12-20 14:38:27 +08:00
parent 193f8301a4
commit 502e114c60
2 changed files with 4 additions and 1 deletions

View File

@ -20,11 +20,12 @@ class GroupsController < ApplicationController
groups = groups.where(automatic: false)
end
count = groups.count
groups = groups.offset(page * page_size).limit(page_size)
render json: {
groups: serialize_data(groups, BasicGroupSerializer),
total_rows_groups: Group.count,
total_rows_groups: count,
load_more_groups: groups_path(page: page + 1)
}
end

View File

@ -26,6 +26,7 @@ describe "Groups" do
expect(group_ids).to include(other_group.id)
expect(group_ids).to_not include(group.id)
expect(response_body["load_more_groups"]).to eq("/groups?page=1")
expect(response_body["total_rows_groups"]).to eq(1)
end
context 'viewing as an admin' do
@ -42,6 +43,7 @@ describe "Groups" do
expect(group_ids).to include(group.id, other_group.id)
expect(response_body["load_more_groups"]).to eq("/groups?page=1")
expect(response_body["total_rows_groups"]).to eq(10)
end
end
end