end
def test_index_sort
- get :index, :sort_key => 'tracker'
+ get :index, :sort => 'tracker,id:desc'
assert_response :success
- sort_params = @request.session['issuesindex_sort']
- assert sort_params.is_a?(Hash)
- assert_equal 'tracker', sort_params[:key]
- assert_equal 'ASC', sort_params[:order]
+ sort_params = @request.session['issues_index_sort']
+ assert sort_params.is_a?(String)
+ assert_equal 'tracker,id:desc', sort_params
+
+ issues = assigns(:issues)
+ assert_not_nil issues
+ assert !issues.empty?
+ assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
end
def test_gantt
class SortHelperTest < HelperTestCase\r
include SortHelper\r
\r
+ def setup\r
+ @session = nil\r
+ @sort_param = nil\r
+ end\r
+ \r
def test_default_sort_clause_with_array\r
sort_init 'attr1', 'desc'\r
sort_update(['attr1', 'attr2'])\r
assert_equal 'table1.attr1 DESC', sort_clause\r
end\r
\r
+ def test_default_sort_clause_with_multiple_columns\r
+ sort_init 'attr1', 'desc'\r
+ sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'})\r
+\r
+ assert_equal 'table1.attr1 DESC, table1.attr2 DESC', sort_clause\r
+ end\r
+ \r
def test_params_sort\r
@sort_param = 'attr1,attr2:desc'\r
\r
end\r
\r
def test_invalid_params_sort\r
- @sort_param = 'attr3'\r
+ @sort_param = 'invalid_key'\r
\r
sort_init 'attr1', 'desc'\r
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})\r
\r
- assert_nil sort_clause\r
- assert_equal '', @session['foo_bar_sort']\r
+ assert_equal 'table1.attr1 DESC', sort_clause\r
+ assert_equal 'attr1:desc', @session['foo_bar_sort']\r
end\r
\r
def test_invalid_order_params_sort\r