From 9cb9f67055ebd97ab348af6b5c2c1df828bc1f74 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 12 Apr 2015 09:44:32 +0000 Subject: [PATCH] SQL error with SQLServer when grouping+sorting issues (#19544). git-svn-id: http://svn.redmine.org/redmine/trunk@14165 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/sort_helper.rb | 13 +++++++++---- test/functional/issues_controller_test.rb | 8 ++++++++ 2 files changed, 17 insertions(+), 4 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 33a85540e..28d4eef14 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 -- 2.39.5