-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[AGILE-314] Order sprints on 'all sprints' by activity #24122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dombesz
merged 2 commits into
release/17.6
from
bug/agile-314-all-sprints-list-is-ordered-incorrectly
Jul 6, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
modules/backlogs/app/models/sprints/scopes/order_by_activity.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| module Sprints::Scopes::OrderByActivity | ||
| extend ActiveSupport::Concern | ||
|
|
||
| class_methods do | ||
| def order_by_activity | ||
| order( | ||
| Arel.sql("CASE status WHEN 'active' THEN 0 WHEN 'in_planning' THEN 1 ELSE 2 END"), | ||
| arel_table[:start_date].desc.nulls_last, | ||
| arel_table[:finish_date].desc.nulls_last, | ||
| arel_table[:name].asc, | ||
| arel_table[:id].asc | ||
| ) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
modules/backlogs/spec/models/sprints/scopes/order_by_activity_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| require "spec_helper" | ||
|
|
||
| RSpec.describe Sprints::Scopes::OrderByActivity do | ||
| shared_let(:project) { create(:project) } | ||
|
|
||
| shared_let(:active_sprint) do | ||
| create(:sprint, project:, status: :active, | ||
| name: "Active sprint", | ||
| start_date: Date.new(2025, 9, 1), | ||
| finish_date: Date.new(2025, 9, 10)) | ||
| end | ||
| shared_let(:in_planning_sprint_later) do | ||
| create(:sprint, project:, status: :in_planning, | ||
| name: "Later planning sprint", | ||
| start_date: Date.new(2025, 9, 11), | ||
| finish_date: Date.new(2025, 9, 20)) | ||
| end | ||
| shared_let(:in_planning_sprint_earlier) do | ||
| create(:sprint, project:, status: :in_planning, | ||
| name: "Earlier planning sprint", | ||
| start_date: Date.new(2025, 9, 1), | ||
| finish_date: Date.new(2025, 9, 10)) | ||
| end | ||
| shared_let(:in_planning_sprint_no_dates) do | ||
| create(:sprint, project:, status: :in_planning, | ||
| name: "No dates planning sprint", | ||
| start_date: nil, | ||
| finish_date: nil) | ||
| end | ||
| shared_let(:completed_sprint_b) do | ||
| create(:sprint, project:, status: :completed, | ||
| name: "Completed sprint B", | ||
| start_date: Date.new(2025, 8, 1), | ||
| finish_date: Date.new(2025, 8, 31)) | ||
| end | ||
| shared_let(:completed_sprint_a) do | ||
| create(:sprint, project:, status: :completed, | ||
| name: "Completed sprint A", | ||
| start_date: Date.new(2025, 8, 1), | ||
| finish_date: Date.new(2025, 8, 31)) | ||
| end | ||
|
|
||
| it "orders active first, then in_planning, then completed" do | ||
| expected_order = [ | ||
| active_sprint, | ||
| in_planning_sprint_later, | ||
| in_planning_sprint_earlier, | ||
| in_planning_sprint_no_dates, | ||
| completed_sprint_a, | ||
| completed_sprint_b | ||
| ] | ||
|
|
||
| expect(Sprint.order_by_activity).to eq(expected_order) | ||
|
EinLama marked this conversation as resolved.
|
||
| end | ||
|
|
||
| it "orders sprints with the same status by start_date descending" do | ||
| expected_order = [ | ||
| in_planning_sprint_later, | ||
| in_planning_sprint_earlier, | ||
| in_planning_sprint_no_dates | ||
| ] | ||
|
|
||
| expect(Sprint.order_by_activity.in_planning).to eq(expected_order) | ||
|
EinLama marked this conversation as resolved.
|
||
| end | ||
|
|
||
| it "places sprints without dates last within their status group" do | ||
| expect(Sprint.order_by_activity.in_planning.last).to eq(in_planning_sprint_no_dates) | ||
|
EinLama marked this conversation as resolved.
|
||
| end | ||
|
|
||
| it "breaks ties within the same status and dates by name ascending" do | ||
| expect(Sprint.order_by_activity.completed).to eq([completed_sprint_a, completed_sprint_b]) | ||
|
EinLama marked this conversation as resolved.
|
||
| end | ||
|
|
||
| it "breaks ties within the same status, dates, and name by id ascending" do | ||
| duplicate_a = create(:sprint, project:, status: :completed, | ||
| name: "Duplicate", | ||
| start_date: Date.new(2025, 8, 1), | ||
| finish_date: Date.new(2025, 8, 31)) | ||
| duplicate_b = create(:sprint, project:, status: :completed, | ||
| name: "Duplicate", | ||
| start_date: Date.new(2025, 8, 1), | ||
| finish_date: Date.new(2025, 8, 31)) | ||
|
|
||
| expect(Sprint.order_by_activity).to include(duplicate_a, duplicate_b) | ||
| idx_a = Sprint.order_by_activity.to_a.index(duplicate_a) | ||
| idx_b = Sprint.order_by_activity.to_a.index(duplicate_b) | ||
| expect(idx_a).to be < idx_b | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.