From 502e114c6026673c4beb14f5b2e6b0e180f9213e Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 20 Dec 2016 14:38:27 +0800 Subject: [PATCH] FIX: Incorrect count when loading more groups. --- app/controllers/groups_controller.rb | 3 ++- spec/integration/groups_spec.rb | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 67b3de9938b..3f339f0d317 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -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 diff --git a/spec/integration/groups_spec.rb b/spec/integration/groups_spec.rb index 348f69f90e9..bedeb75e0ac 100644 --- a/spec/integration/groups_spec.rb +++ b/spec/integration/groups_spec.rb @@ -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