From fa33b8c2966bb042f4552525ba47ba1a2b149d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 19 Feb 2020 14:27:55 +0100 Subject: [PATCH] [32296] Also ensure versions are sorted by name If versions are not sorted by date, the default work_packages.id sort will break up grouped versions if they have no date. https://community.openproject.com/wp/32296 --- app/models/queries/work_packages/columns/property_column.rb | 2 +- app/models/version.rb | 3 ++- spec/models/query/sort_criteria_spec.rb | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/queries/work_packages/columns/property_column.rb b/app/models/queries/work_packages/columns/property_column.rb index f510b2995e..6c57a16b4c 100644 --- a/app/models/queries/work_packages/columns/property_column.rb +++ b/app/models/queries/work_packages/columns/property_column.rb @@ -97,7 +97,7 @@ class Queries::WorkPackages::Columns::PropertyColumn < Queries::WorkPackages::Co }, fixed_version: { association: 'fixed_version', - sortable: %w(start_date effective_date), + sortable: %w(start_date effective_date name), default_order: 'DESC', null_handling: 'NULLS LAST', groupable: "#{WorkPackage.table_name}.fixed_version_id" diff --git a/app/models/version.rb b/app/models/version.rb index 98207a66f0..2b673d96ab 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -60,7 +60,8 @@ class Version < ActiveRecord::Base scope :order_by_newest_date, -> { reorder Arel.sql("#{Version.table_name}.start_date DESC NULLS LAST, - #{Version.table_name}.effective_date DESC NULLS LAST") + #{Version.table_name}.effective_date DESC NULLS LAST, + #{Version.table_name}.name ASC") } def self.with_status_open diff --git a/spec/models/query/sort_criteria_spec.rb b/spec/models/query/sort_criteria_spec.rb index d0d349aaa1..594c8486b0 100644 --- a/spec/models/query/sort_criteria_spec.rb +++ b/spec/models/query/sort_criteria_spec.rb @@ -77,7 +77,8 @@ describe ::Query::SortCriteria, type: :model, with_mail: false do it 'adds the order handling' do expect(subject.length).to eq 2 - expect(subject.first).to eq ['start_date DESC NULLS LAST', 'effective_date DESC NULLS LAST'] + expect(subject.first) + .to eq ['start_date DESC NULLS LAST', 'effective_date DESC NULLS LAST', 'name DESC NULLS LAST'] expect(subject.last).to eq ['work_packages.start_date NULLS LAST'] end end