summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-04-25 07:37:46 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-04-25 07:37:46 +0000
commit873dff0d364e4e1bfbded5103174737f0479504f (patch)
tree00a3fa98af55a3a8d4c4310ea29799af1837f2b7
parent94910b1e0924905409c8942f64821aec84a903ac (diff)
downloadredmine-873dff0d364e4e1bfbded5103174737f0479504f.tar.gz
redmine-873dff0d364e4e1bfbded5103174737f0479504f.zip
Merged r14165 and r14166 (#19544).
git-svn-id: http://svn.redmine.org/redmine/branches/3.0-stable@14207 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/helpers/sort_helper.rb13
-rw-r--r--test/functional/issues_controller_test.rb8
-rw-r--r--test/unit/helpers/sort_helper_test.rb4
3 files changed, 19 insertions, 6 deletions
diff --git a/app/helpers/sort_helper.rb b/app/helpers/sort_helper.rb
index c9da9bd10..d6ac8bd22 100644
--- a/app/helpers/sort_helper.rb
+++ b/app/helpers/sort_helper.rb
@@ -85,7 +85,7 @@ module SortHelper
sql = @criteria.collect do |k,o|
if s = @available_criteria[k]
s = [s] unless s.is_a?(Array)
- (o ? s : s.collect {|c| append_desc(c)})
+ s.collect {|c| append_order(c, o ? "ASC" : "DESC")}
end
end.flatten.compact
sql.blank? ? nil : sql
@@ -129,14 +129,19 @@ module SortHelper
self
end
- # Appends DESC to the sort criterion unless it has a fixed order
- def append_desc(criterion)
+ # Appends ASC/DESC to the sort criterion unless it has a fixed order
+ def append_order(criterion, order)
if criterion =~ / (asc|desc)$/i
criterion
else
- "#{criterion} DESC"
+ "#{criterion} #{order}"
end
end
+
+ # Appends DESC to the sort criterion unless it has a fixed order
+ def append_desc(criterion)
+ append_order(criterion, "DESC")
+ end
end
def sort_name
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 7685dc127..488b8d868 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -265,6 +265,14 @@ class IssuesControllerTest < ActionController::TestCase
assert_not_nil assigns(:issue_count_by_group)
end
+ def test_index_with_query_grouped_and_sorted_by_category
+ get :index, :project_id => 1, :set_filter => 1, :group_by => "category", :sort => "category"
+ assert_response :success
+ assert_template 'index'
+ assert_not_nil assigns(:issues)
+ assert_not_nil assigns(:issue_count_by_group)
+ end
+
def test_index_with_query_grouped_by_list_custom_field
get :index, :project_id => 1, :query_id => 9
assert_response :success
diff --git a/test/unit/helpers/sort_helper_test.rb b/test/unit/helpers/sort_helper_test.rb
index 600abdd4a..4f4ae3d78 100644
--- a/test/unit/helpers/sort_helper_test.rb
+++ b/test/unit/helpers/sort_helper_test.rb
@@ -54,7 +54,7 @@ class SortHelperTest < ActionView::TestCase
sort_init 'attr1', 'desc'
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
- assert_equal ['table1.attr1', 'table2.attr2 DESC'], sort_clause
+ assert_equal ['table1.attr1 ASC', 'table2.attr2 DESC'], sort_clause
assert_equal 'attr1,attr2:desc', @session['foo_bar_sort']
end
@@ -74,7 +74,7 @@ class SortHelperTest < ActionView::TestCase
sort_init 'attr1', 'desc'
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
- assert_equal ['table1.attr1', 'table2.attr2'], sort_clause
+ assert_equal ['table1.attr1 ASC', 'table2.attr2 ASC'], sort_clause
assert_equal 'attr1,attr2', @session['foo_bar_sort']
end