Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix counting on multiple columns for project

Oliver Günther9ec1e058914d
diff --git a/lib/api/decorators/offset_paginated_collection.rb b/lib/api/decorators/offset_paginated_collection.rb
index b5f58fc7b9c..ead34ed1cf4 100644
--- a/lib/api/decorators/offset_paginated_collection.rb
+++ b/lib/api/decorators/offset_paginated_collection.rb
@@ -46,7 +46,7 @@ module API
full_self_link = make_page_link(page: @page, page_size: @per_page)
paged = paged_models(models)
- super(paged, models.count, self_link: full_self_link, current_user: current_user, groups: groups)
+ super(paged, total_count(models), self_link: full_self_link, current_user: current_user, groups: groups)
end
link :jumpTo do
@@ -87,6 +87,12 @@ module API
exec_context: :decorator,
getter: ->(*) { @page }
+ protected
+
+ def total_count(models)
+ models.count(:id)
+ end
+
private
def make_page_link(page:, page_size:)
diff --git a/modules/dashboards/spec/features/subprojects_spec.rb b/modules/dashboards/spec/features/subprojects_spec.rb
index 4cddfecee22..315a59cd920 100644
--- a/modules/dashboards/spec/features/subprojects_spec.rb
+++ b/modules/dashboards/spec/features/subprojects_spec.rb
@@ -82,6 +82,9 @@ describe 'Subprojects widget on dashboard', type: :feature, js: true do
subprojects_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
+ expect(page)
+ .to have_link(child_project.name, wait: 10)
+
within(subprojects_widget.area) do
expect(page)
.to have_link(child_project.name)
diff --git a/spec/lib/api/v3/groups/group_collection_representer_spec.rb b/spec/lib/api/v3/groups/group_collection_representer_spec.rb
index eb2e2a138a0..56bf6e22000 100644
--- a/spec/lib/api/v3/groups/group_collection_representer_spec.rb
+++ b/spec/lib/api/v3/groups/group_collection_representer_spec.rb
@@ -41,6 +41,10 @@ describe ::API::V3::Groups::GroupCollectionRepresenter do
.to receive(:page)
.with(page)
.and_return(groups)
+
+ allow(groups)
+ .to receive(:count)
+ .and_return(total)
end
end
let(:current_user) { FactoryBot.build_stubbed(:user) }
diff --git a/spec/lib/api/v3/memberships/membership_collection_representer_spec.rb b/spec/lib/api/v3/memberships/membership_collection_representer_spec.rb
index beca6a1d185..c686144d211 100644
--- a/spec/lib/api/v3/memberships/membership_collection_representer_spec.rb
+++ b/spec/lib/api/v3/memberships/membership_collection_representer_spec.rb
@@ -41,6 +41,10 @@ describe ::API::V3::Memberships::MembershipCollectionRepresenter do
.to receive(:page)
.with(page)
.and_return(members)
+
+ allow(members)
+ .to receive(:count)
+ .and_return(3)
end
end
let(:current_user) { FactoryBot.build_stubbed(:user) }
diff --git a/spec/lib/api/v3/notifications/notification_collection_representer_spec.rb b/spec/lib/api/v3/notifications/notification_collection_representer_spec.rb
index c051cb5c6bf..744e54e5573 100644
--- a/spec/lib/api/v3/notifications/notification_collection_representer_spec.rb
+++ b/spec/lib/api/v3/notifications/notification_collection_representer_spec.rb
@@ -43,6 +43,10 @@ describe ::API::V3::Notifications::NotificationCollectionRepresenter do
.to receive(:page)
.with(page)
.and_return(items)
+
+ allow(items)
+ .to receive(:count)
+ .and_return(total)
end
end
let(:current_user) { FactoryBot.build_stubbed(:user) }
diff --git a/spec/lib/api/v3/placeholder_users/placeholder_user_collection_representer_spec.rb b/spec/lib/api/v3/placeholder_users/placeholder_user_collection_representer_spec.rb
index 5eff556a927..da1127de072 100644
--- a/spec/lib/api/v3/placeholder_users/placeholder_user_collection_representer_spec.rb
+++ b/spec/lib/api/v3/placeholder_users/placeholder_user_collection_representer_spec.rb
@@ -50,6 +50,10 @@ describe ::API::V3::PlaceholderUsers::PlaceholderUserCollectionRepresenter do
.with(page)
.and_return(placeholders)
+ allow(placeholders)
+ .to receive(:count)
+ .and_return(total)
+
placeholders
end
diff --git a/spec/lib/api/v3/users/paginated_user_collection_representer_spec.rb b/spec/lib/api/v3/users/paginated_user_collection_representer_spec.rb
index fd477f128af..8d3997a8085 100644
--- a/spec/lib/api/v3/users/paginated_user_collection_representer_spec.rb
+++ b/spec/lib/api/v3/users/paginated_user_collection_representer_spec.rb
@@ -49,6 +49,10 @@ describe ::API::V3::Users::PaginatedUserCollectionRepresenter do
.with(page)
.and_return(users)
+ allow(users)
+ .to receive(:count)
+ .and_return(total)
+
users
end