]> source.dussan.org Git - redmine.git/commitdiff
Adds firstname initials+lastname user format.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 24 Jan 2014 09:23:11 +0000 (09:23 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 24 Jan 2014 09:23:11 +0000 (09:23 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12690 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/user.rb
test/unit/user_test.rb

index 189a9d9d6e3ccdfa4c40840acfd6ac82b511c489..d04369277ca813533f70d6a7b104143869ad4a0b 100644 (file)
@@ -32,6 +32,11 @@ class User < Principal
         :order => %w(firstname lastname id),
         :setting_order => 2
       },
+    :firstinitial_lastname => {
+        :string => '#{firstname.to_s.gsub(/(([[:alpha:]])[[:alpha:]]*\.?)/, \'\2.\')} #{lastname}',
+        :order => %w(firstname lastname id),
+        :setting_order => 2
+      },
     :firstname => {
         :string => '#{firstname}',
         :order => %w(firstname id),
index 4e11ffecc94b4b20ed80c84f4801d705794b24e0..6e995b7e2e605359a50be737d4c161c850eb21c0 100644 (file)
@@ -442,6 +442,11 @@ class UserTest < ActiveSupport::TestCase
   def test_name_format
     assert_equal 'John S.', @jsmith.name(:firstname_lastinitial)
     assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname)
+    assert_equal 'J. Smith', @jsmith.name(:firstinitial_lastname)
+    assert_equal 'J.-P. Lang', User.new(:firstname => 'Jean-Philippe', :lastname => 'Lang').name(:firstinitial_lastname)
+  end
+
+  def test_name_should_use_setting_as_default_format
     with_settings :user_format => :firstname_lastname do
       assert_equal 'John Smith', @jsmith.reload.name
     end