Fixing tests (sort refactoring).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2577 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-03-12 18:43:19 +00:00
parent 1852d907ba
commit adbe164246
2 changed files with 24 additions and 8 deletions

View File

@ -197,13 +197,17 @@ class IssuesControllerTest < Test::Unit::TestCase
end end
def test_index_sort def test_index_sort
get :index, :sort_key => 'tracker' get :index, :sort => 'tracker,id:desc'
assert_response :success assert_response :success
sort_params = @request.session['issuesindex_sort'] sort_params = @request.session['issues_index_sort']
assert sort_params.is_a?(Hash) assert sort_params.is_a?(String)
assert_equal 'tracker', sort_params[:key] assert_equal 'tracker,id:desc', sort_params
assert_equal 'ASC', sort_params[:order]
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 end
def test_gantt def test_gantt

View File

@ -20,6 +20,11 @@ require File.dirname(__FILE__) + '/../../test_helper'
class SortHelperTest < HelperTestCase class SortHelperTest < HelperTestCase
include SortHelper include SortHelper
def setup
@session = nil
@sort_param = nil
end
def test_default_sort_clause_with_array def test_default_sort_clause_with_array
sort_init 'attr1', 'desc' sort_init 'attr1', 'desc'
sort_update(['attr1', 'attr2']) sort_update(['attr1', 'attr2'])
@ -34,6 +39,13 @@ class SortHelperTest < HelperTestCase
assert_equal 'table1.attr1 DESC', sort_clause assert_equal 'table1.attr1 DESC', sort_clause
end end
def test_default_sort_clause_with_multiple_columns
sort_init 'attr1', 'desc'
sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'})
assert_equal 'table1.attr1 DESC, table1.attr2 DESC', sort_clause
end
def test_params_sort def test_params_sort
@sort_param = 'attr1,attr2:desc' @sort_param = 'attr1,attr2:desc'
@ -45,13 +57,13 @@ class SortHelperTest < HelperTestCase
end end
def test_invalid_params_sort def test_invalid_params_sort
@sort_param = 'attr3' @sort_param = 'invalid_key'
sort_init 'attr1', 'desc' sort_init 'attr1', 'desc'
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
assert_nil sort_clause assert_equal 'table1.attr1 DESC', sort_clause
assert_equal '', @session['foo_bar_sort'] assert_equal 'attr1:desc', @session['foo_bar_sort']
end end
def test_invalid_order_params_sort def test_invalid_order_params_sort