]> source.dussan.org Git - redmine.git/commitdiff
Remove duplicate keys from sort criteria (#32737).
authorGo MAEDA <maeda@farend.jp>
Thu, 2 Apr 2020 06:22:23 +0000 (06:22 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 2 Apr 2020 06:22:23 +0000 (06:22 +0000)
Patch by Go MAEDA.

git-svn-id: http://svn.redmine.org/redmine/trunk@19636 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/sort_criteria.rb
test/unit/query_test.rb

index efe40514bc58b26d53bedf703ebe79a4f7373a1d..4de81900ea4579790f5038abeb5768187700fe58 100644 (file)
@@ -90,6 +90,7 @@ module Redmine
 
     def normalize!
       self.reject! {|s| s.first.blank? }
+      self.uniq! {|s| s.first }
       self.collect! {|s| s = Array(s); [s.first, (s.last == false || s.last.to_s == 'desc') ? 'desc' : 'asc']}
       self.replace self.first(3)
     end
index d20fefce46499e7c8fb91f318999189030213273..0759a447b24407766dd29e9adbab456e690ba50f 100644 (file)
@@ -1640,12 +1640,12 @@ class QueryTest < ActiveSupport::TestCase
   def test_sort_criteria_should_have_only_first_three_elements
     q = IssueQuery.new
     q.sort_criteria = [['priority', 'desc'], ['tracker', 'asc'], ['priority', 'asc'], ['id', 'asc'], ['project', 'asc'], ['subject', 'asc']]
-    assert_equal [['priority', 'desc'], ['tracker', 'asc'], ['priority', 'asc']], q.sort_criteria
+    assert_equal [['priority', 'desc'], ['tracker', 'asc'], ['id', 'asc']], q.sort_criteria
   end
 
-  def test_sort_criteria_should_remove_blank_keys
+  def test_sort_criteria_should_remove_blank_or_duplicate_keys
     q = IssueQuery.new
-    q.sort_criteria = [['priority', 'desc'], [nil, 'desc'], ['', 'asc'], ['project', 'asc']]
+    q.sort_criteria = [['priority', 'desc'], [nil, 'desc'], ['', 'asc'], ['priority', 'asc'], ['project', 'asc']]
     assert_equal [['priority', 'desc'], ['project', 'asc']], q.sort_criteria
   end