Sort the issue list by author/assignee according to user display format (#9669).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7938 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2011-11-26 17:37:20 +00:00
parent 0293ba7e9f
commit 5a1fcf826f
6 changed files with 107 additions and 18 deletions
+33 -5
View File
@@ -276,11 +276,6 @@ class IssuesControllerTest < ActionController::TestCase
assert_response :success
end
def test_index_sort_by_field_not_included_in_columns
Setting.issue_list_default_columns = %w(subject author)
get :index, :sort => 'tracker'
end
def test_index_csv
get :index, :format => 'csv'
assert_response :success
@@ -421,10 +416,43 @@ class IssuesControllerTest < ActionController::TestCase
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_index_sort_by_field_not_included_in_columns
Setting.issue_list_default_columns = %w(subject author)
get :index, :sort => 'tracker'
end
def test_index_sort_by_assigned_to
get :index, :sort => 'assigned_to'
assert_response :success
assignees = assigns(:issues).collect(&:assigned_to).compact
assert_equal assignees.sort, assignees
end
def test_index_sort_by_assigned_to_desc
get :index, :sort => 'assigned_to:desc'
assert_response :success
assignees = assigns(:issues).collect(&:assigned_to).compact
assert_equal assignees.sort.reverse, assignees
end
def test_index_group_by_assigned_to
get :index, :group_by => 'assigned_to', :sort => 'priority'
assert_response :success
end
def test_index_sort_by_author
get :index, :sort => 'author'
assert_response :success
authors = assigns(:issues).collect(&:author)
assert_equal authors.sort, authors
end
def test_index_sort_by_author_desc
get :index, :sort => 'author:desc'
assert_response :success
authors = assigns(:issues).collect(&:author)
assert_equal authors.sort.reverse, authors
end
def test_index_group_by_author
+2 -2
View File
@@ -98,11 +98,11 @@ class ActiveSupport::TestCase
end
def with_settings(options, &block)
saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h}
saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].is_a?(Symbol) ? Setting[k] : Setting[k].dup; h}
options.each {|k, v| Setting[k] = v}
yield
ensure
saved_settings.each {|k, v| Setting[k] = v}
saved_settings.each {|k, v| Setting[k] = v} if saved_settings
end
def change_user_password(login, new_password)
+16
View File
@@ -443,6 +443,22 @@ class QueryTest < ActiveSupport::TestCase
assert_nil q.group_by_column
assert_nil q.group_by_statement
end
def test_sortable_columns_should_sort_assignees_according_to_user_format_setting
with_settings :user_format => 'lastname_coma_firstname' do
q = Query.new
assert q.sortable_columns.has_key?('assigned_to')
assert_equal %w(users.lastname users.firstname users.id), q.sortable_columns['assigned_to']
end
end
def test_sortable_columns_should_sort_authors_according_to_user_format_setting
with_settings :user_format => 'lastname_coma_firstname' do
q = Query.new
assert q.sortable_columns.has_key?('author')
assert_equal %w(authors.lastname authors.firstname authors.id), q.sortable_columns['author']
end
end
def test_default_sort
q = Query.new
+24
View File
@@ -397,6 +397,30 @@ class UserTest < ActiveSupport::TestCase
Setting.user_format = :username
assert_equal 'jsmith', @jsmith.reload.name
end
def test_fields_for_order_statement_should_return_fields_according_user_format_setting
with_settings :user_format => 'lastname_coma_firstname' do
assert_equal ['users.lastname', 'users.firstname', 'users.id'], User.fields_for_order_statement
end
end
def test_fields_for_order_statement_width_table_name_should_prepend_table_name
with_settings :user_format => 'lastname_firstname' do
assert_equal ['authors.lastname', 'authors.firstname', 'authors.id'], User.fields_for_order_statement('authors')
end
end
def test_fields_for_order_statement_with_blank_format_should_return_default
with_settings :user_format => '' do
assert_equal ['users.firstname', 'users.lastname', 'users.id'], User.fields_for_order_statement
end
end
def test_fields_for_order_statement_with_invalid_format_should_return_default
with_settings :user_format => 'foo' do
assert_equal ['users.firstname', 'users.lastname', 'users.id'], User.fields_for_order_statement
end
end
def test_lock
user = User.try_to_login("jsmith", "jsmith")