]> source.dussan.org Git - redmine.git/commitdiff
Merged r9449 from trunk.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 20 Apr 2012 06:14:32 +0000 (06:14 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 20 Apr 2012 06:14:32 +0000 (06:14 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@9454 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 86820769799fc160001c561f0090a44175affade..99eda64750cbbbb2cb28382b2d3ebbc2cdb701b6 100644 (file)
@@ -68,7 +68,7 @@ class User < Principal
   MAIL_LENGTH_LIMIT = 60
 
   validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
-  validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? }, :case_sensitive => false
+  validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, :case_sensitive => false
   validates_uniqueness_of :mail, :if => Proc.new { |user| !user.mail.blank? }, :case_sensitive => false
   # Login must contain lettres, numbers, underscores only
   validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i
index a78cb3c70623067d808d4a87cc786b957f74a5d9..23692bfdf47a9e6950dcb74eee96a26861dbe21b 100644 (file)
@@ -134,6 +134,20 @@ class UserTest < ActiveSupport::TestCase
     assert_equal "john", @admin.login
   end
 
+  def test_update_should_not_fail_for_legacy_user_with_different_case_logins
+    u1 = User.new(:firstname => "new", :lastname => "user", :mail => "newuser1@somenet.foo")
+    u1.login = 'newuser1'
+    assert u1.save
+
+    u2 = User.new(:firstname => "new", :lastname => "user", :mail => "newuser2@somenet.foo")
+    u2.login = 'newuser1'
+    assert u2.save(false)
+
+    user = User.find(u2.id)
+    user.firstname = "firstname"
+    assert user.save, "Save failed"
+  end
+
   def test_destroy_should_delete_members_and_roles
     members = Member.find_all_by_user_id(2)
     ms = members.size