Project

General

Profile

Patch #29632 » restrict_the_number_of_elements_of_sort_criteria.patch

Mizuki ISHIKAWA, 2018-09-18 09:44

View differences:

lib/redmine/sort_criteria.rb
88 88

  
89 89
    def normalize!
90 90
      self.collect! {|s| s = Array(s); [s.first, (s.last == false || s.last.to_s == 'desc') ? 'desc' : 'asc']}
91
      self.slice!(3)
92
      self
91
      self.replace self.first(3)
93 92
    end
94 93

  
95 94
    # Appends ASC/DESC to the sort criterion unless it has a fixed order
test/unit/query_test.rb
1490 1490
    assert_equal [['id', 'desc']], q.sort_criteria
1491 1491
  end
1492 1492

  
1493
  def test_sort_criteria_should_have_no_more_than_three_elements
1494
    q = IssueQuery.new
1495
    q.sort_criteria = [['priority', 'desc'], ['tracker', 'asc'], ['priority', 'asc'], ['id', 'asc'], ['project', 'asc'], ['subject', 'asc']]
1496
    assert_equal [['priority', 'desc'], ['tracker', 'asc'], ['priority', 'asc']], q.sort_criteria
1497
  end
1498

  
1493 1499
  def test_set_sort_criteria_with_hash
1494 1500
    q = IssueQuery.new
1495 1501
    q.sort_criteria = {'0' => ['priority', 'desc'], '2' => ['tracker']}
(2-2/2)