summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-01-23 17:44:28 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-01-23 17:44:28 +0000
commite53a5de918c1db1f409df8d72a0cb5f38b4c7671 (patch)
treebea491687e40e92fa1713da2ba363cece392a24e /test
parentc7df78f3b6aee78403e8563b504e10770270fb24 (diff)
downloadredmine-e53a5de918c1db1f409df8d72a0cb5f38b4c7671.tar.gz
redmine-e53a5de918c1db1f409df8d72a0cb5f38b4c7671.zip
Adds "sorted" scope to Principal and User and sort users/groups properly.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11259 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/unit/principal_test.rb14
-rw-r--r--test/unit/user_test.rb4
2 files changed, 18 insertions, 0 deletions
diff --git a/test/unit/principal_test.rb b/test/unit/principal_test.rb
index b96e786e9..8cd511ea2 100644
--- a/test/unit/principal_test.rb
+++ b/test/unit/principal_test.rb
@@ -49,6 +49,20 @@ class PrincipalTest < ActiveSupport::TestCase
assert_equal [], Principal.not_member_of([]).sort
end
+ def test_sorted_scope_should_sort_users_before_groups
+ scope = Principal.where("type <> ?", 'AnonymousUser')
+ expected_order = scope.all.sort do |a, b|
+ if a.is_a?(User) && b.is_a?(Group)
+ -1
+ elsif a.is_a?(Group) && b.is_a?(User)
+ 1
+ else
+ a.name.downcase <=> b.name.downcase
+ end
+ end
+ assert_equal expected_order.map(&:name).map(&:downcase), scope.sorted.all.map(&:name).map(&:downcase)
+ end
+
context "#like" do
setup do
Principal.create!(:login => 'login')
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index bf74dd6da..c0e51d469 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -34,6 +34,10 @@ class UserTest < ActiveSupport::TestCase
@dlopper = User.find(3)
end
+ def test_sorted_scope_should_sort_user_by_display_name
+ assert_equal User.all.map(&:name).map(&:downcase).sort, User.sorted.all.map(&:name).map(&:downcase)
+ end
+
def test_generate
User.generate!(:firstname => 'Testing connection')
User.generate!(:firstname => 'Testing connection')