##// END OF EJS Templates
Merged r14165 and r14166 (#19544)....
Jean-Philippe Lang -
r13825:873dff0d364e
parent child
Show More
@@ -85,7 +85,7 module SortHelper
85 sql = @criteria.collect do |k,o|
85 sql = @criteria.collect do |k,o|
86 if s = @available_criteria[k]
86 if s = @available_criteria[k]
87 s = [s] unless s.is_a?(Array)
87 s = [s] unless s.is_a?(Array)
88 (o ? s : s.collect {|c| append_desc(c)})
88 s.collect {|c| append_order(c, o ? "ASC" : "DESC")}
89 end
89 end
90 end.flatten.compact
90 end.flatten.compact
91 sql.blank? ? nil : sql
91 sql.blank? ? nil : sql
@@ -129,14 +129,19 module SortHelper
129 self
129 self
130 end
130 end
131
131
132 # Appends DESC to the sort criterion unless it has a fixed order
132 # Appends ASC/DESC to the sort criterion unless it has a fixed order
133 def append_desc(criterion)
133 def append_order(criterion, order)
134 if criterion =~ / (asc|desc)$/i
134 if criterion =~ / (asc|desc)$/i
135 criterion
135 criterion
136 else
136 else
137 "#{criterion} DESC"
137 "#{criterion} #{order}"
138 end
138 end
139 end
139 end
140
141 # Appends DESC to the sort criterion unless it has a fixed order
142 def append_desc(criterion)
143 append_order(criterion, "DESC")
144 end
140 end
145 end
141
146
142 def sort_name
147 def sort_name
@@ -265,6 +265,14 class IssuesControllerTest < ActionController::TestCase
265 assert_not_nil assigns(:issue_count_by_group)
265 assert_not_nil assigns(:issue_count_by_group)
266 end
266 end
267
267
268 def test_index_with_query_grouped_and_sorted_by_category
269 get :index, :project_id => 1, :set_filter => 1, :group_by => "category", :sort => "category"
270 assert_response :success
271 assert_template 'index'
272 assert_not_nil assigns(:issues)
273 assert_not_nil assigns(:issue_count_by_group)
274 end
275
268 def test_index_with_query_grouped_by_list_custom_field
276 def test_index_with_query_grouped_by_list_custom_field
269 get :index, :project_id => 1, :query_id => 9
277 get :index, :project_id => 1, :query_id => 9
270 assert_response :success
278 assert_response :success
@@ -54,7 +54,7 class SortHelperTest < ActionView::TestCase
54 sort_init 'attr1', 'desc'
54 sort_init 'attr1', 'desc'
55 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
55 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
56
56
57 assert_equal ['table1.attr1', 'table2.attr2 DESC'], sort_clause
57 assert_equal ['table1.attr1 ASC', 'table2.attr2 DESC'], sort_clause
58 assert_equal 'attr1,attr2:desc', @session['foo_bar_sort']
58 assert_equal 'attr1,attr2:desc', @session['foo_bar_sort']
59 end
59 end
60
60
@@ -74,7 +74,7 class SortHelperTest < ActionView::TestCase
74 sort_init 'attr1', 'desc'
74 sort_init 'attr1', 'desc'
75 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
75 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
76
76
77 assert_equal ['table1.attr1', 'table2.attr2'], sort_clause
77 assert_equal ['table1.attr1 ASC', 'table2.attr2 ASC'], sort_clause
78 assert_equal 'attr1,attr2', @session['foo_bar_sort']
78 assert_equal 'attr1,attr2', @session['foo_bar_sort']
79 end
79 end
80
80
General Comments 0
You need to be logged in to leave comments. Login now