From 6a8be88ad613bcb2a2fa0189cbac0b68742dc357 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 11 Nov 2008 12:59:28 +0000 Subject: [PATCH] Sort users by their display names so that user dropdown lists are sorted alphabetically (#2015). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2010 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .loadpath | 5 +++++ .project | 18 ++++++++++++++++++ .settings/org.eclipse.core.resources.prefs | 5 +++++ app/models/user.rb | 17 ++++++++--------- test/unit/user_test.rb | 4 ++-- 5 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 .loadpath create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs diff --git a/.loadpath b/.loadpath new file mode 100644 index 000000000..c4415b3d0 --- /dev/null +++ b/.loadpath @@ -0,0 +1,5 @@ + + + + + diff --git a/.project b/.project new file mode 100644 index 000000000..6a0b4c407 --- /dev/null +++ b/.project @@ -0,0 +1,18 @@ + + + trunk_fixes + + + + + + org.rubypeople.rdt.core.rubybuilder + + + + + + org.rubypeople.rdt.core.rubynature + org.radrails.rails.core.railsnature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 000000000..69197b5bd --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +#Sun Nov 09 21:42:24 CET 2008 +eclipse.preferences.version=1 +encoding//app/helpers/ifpdf_helper.rb=UTF-8 +encoding//test/fixtures/mail_handler=UTF-8 +encoding/lang=UTF-8 diff --git a/app/models/user.rb b/app/models/user.rb index f468063ed..53453c0dc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -71,6 +71,11 @@ class User < ActiveRecord::Base # update hashed_password if password was set self.hashed_password = User.hash_password(self.password) if self.password end + + def reload(*args) + @name = nil + super + end def self.active with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do @@ -120,8 +125,7 @@ class User < ActiveRecord::Base # Return user's full name for display def name(formatter = nil) - f = USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname] - eval '"' + f + '"' + @name ||= eval('"' + (USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname]) + '"') end def active? @@ -180,14 +184,9 @@ class User < ActiveRecord::Base token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil end + # Sort users by their display names def <=>(user) - if user.nil? - -1 - elsif lastname.to_s.downcase == user.lastname.to_s.downcase - firstname.to_s.downcase <=> user.firstname.to_s.downcase - else - lastname.to_s.downcase <=> user.lastname.to_s.downcase - end + self.to_s.downcase <=> user.to_s.downcase end def to_s diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 80011f4bf..b931501a1 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -85,9 +85,9 @@ class UserTest < Test::Unit::TestCase def test_name_format assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname) Setting.user_format = :firstname_lastname - assert_equal 'John Smith', @jsmith.name + assert_equal 'John Smith', @jsmith.reload.name Setting.user_format = :username - assert_equal 'jsmith', @jsmith.name + assert_equal 'jsmith', @jsmith.reload.name end def test_lock -- 2.39.5