From 1fb2bfbd854f272b0fdb10016dfb5b7064e670d4 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Sun, 25 Nov 2018 20:34:33 +0000 Subject: [PATCH] Remove blank keys from sort criterias --- lib/redmine/sort_criteria.rb | 1 + test/unit/query_test.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/redmine/sort_criteria.rb b/lib/redmine/sort_criteria.rb index 2a69694..c89ef03 100644 --- a/lib/redmine/sort_criteria.rb +++ b/lib/redmine/sort_criteria.rb @@ -87,6 +87,7 @@ module Redmine private def normalize! + self.reject! {|s| s.first.blank? } self.collect! {|s| s = Array(s); [s.first, (s.last == false || s.last.to_s == 'desc') ? 'desc' : 'asc']} self.replace self.first(3) end diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 1a66bc4..e868ef4 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -1496,6 +1496,12 @@ class QueryTest < ActiveSupport::TestCase assert_equal [['priority', 'desc'], ['tracker', 'asc'], ['priority', 'asc']], q.sort_criteria end + def test_sort_criteria_should_remove_blank_keys + q = IssueQuery.new + q.sort_criteria = [['priority', 'desc'], [nil, 'desc'], ['', 'asc'], ['project', 'asc']] + assert_equal [['priority', 'desc'], ['project', 'asc']], q.sort_criteria + end + def test_set_sort_criteria_with_hash q = IssueQuery.new q.sort_criteria = {'0' => ['priority', 'desc'], '2' => ['tracker']} -- 2.1.4