]> source.dussan.org Git - redmine.git/commitdiff
Merged r19655 to 4.1-stable (#33110).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 5 Apr 2020 11:20:58 +0000 (11:20 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 5 Apr 2020 11:20:58 +0000 (11:20 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@19665 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
test/unit/query_test.rb

index 36c93882071090ecd12e4f9482d4e35176299141..0dec7d2118e7bdbcfb09e0510e9834d5cf9b843b 100644 (file)
@@ -842,7 +842,12 @@ class Query < ActiveRecord::Base
   def group_by_sort_order
     if column = group_by_column
       order = (sort_criteria.order_for(column.name) || column.default_order || 'asc').try(:upcase)
-      Array(column.sortable).map {|s| Arel.sql("#{s} #{order}")}
+
+      column_sortable = column.sortable
+      if column.is_a?(TimestampQueryColumn)
+        column_sortable = Redmine::Database.timestamp_to_date(column.sortable, User.current.time_zone)
+      end
+      Array(column_sortable).map {|s| Arel.sql("#{s} #{order}")}
     end
   end
 
index cc5a23530e92cfbeb59cba105f435fb4790655a2..8953982640b22ce0cbbb33380e9fb3f5bcb77525 100644 (file)
@@ -1703,6 +1703,34 @@ class QueryTest < ActiveSupport::TestCase
     assert_equal values.sort, values
   end
 
+  def test_sort_with_group_by_timestamp_query_column_should_sort_after_date_value
+    User.current = User.find(1)
+
+    # Touch Issue#10 in order to be the last updated issue
+    Issue.find(10).update_attribute(:updated_on, Issue.find(10).updated_on + 1)
+
+    q = IssueQuery.new(
+      :name => '_',
+      :filters => { 'updated_on' => {:operator => 't', :values => ['']} },
+      :group_by => 'updated_on',
+      :sort_criteria => [['subject', 'asc']]
+    )
+
+    # The following 3 issues are updated today (ordered by updated_on):
+    #   Issue#10: Issue Doing the Blocking
+    #   Issue#9: Blocked Issue
+    #   Issue#6: Issue of a private subproject
+
+    # When we group by a timestamp query column, all the issues in the group have the same date value (today)
+    # and the time of the value should not be taken into consideration when sorting
+    #
+    # For the same issues after subject ascending should return the following:
+    # Issue#9: Blocked Issue
+    # Issue#10: Issue Doing the Blocking
+    # Issue#6: Issue of a private subproject
+    assert_equal [9, 10, 6], q.issues.map(&:id)
+  end
+
   def test_sort_by_total_for_estimated_hours
     # Prepare issues
     parent = issues(:issues_001)