]> source.dussan.org Git - redmine.git/commitdiff
Makes email adress uniqueness case-insensitive (#2473).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 10 Jan 2009 11:29:35 +0000 (11:29 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 10 Jan 2009 11:29:35 +0000 (11:29 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2253 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 96923900e59160c69cd8aa49de8ba41a145fce15..0005c85d10b34777bdb223d300cf87d287cf9c4e 100644 (file)
@@ -54,7 +54,7 @@ class User < ActiveRecord::Base
        
   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? }
-  validates_uniqueness_of :mail, :if => Proc.new { |user| !user.mail.blank? }
+  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
   validates_length_of :login, :maximum => 30
index 319a1c2f44d6a0bb10838b05a57f516f5f554249..e8500623a13506185452bbdfdf09af459c8e4550 100644 (file)
@@ -47,6 +47,19 @@ class UserTest < Test::Unit::TestCase
 \r
     user.password, user.password_confirmation = "password", "password"\r
     assert user.save\r
+  end
+  
+  def test_mail_uniqueness_should_not_be_case_sensitive
+    u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
+    u.login = 'newuser1'
+    u.password, u.password_confirmation = "password", "password"
+    assert u.save
+    
+    u = User.new(:firstname => "new", :lastname => "user", :mail => "newUser@Somenet.foo")
+    u.login = 'newuser2'
+    u.password, u.password_confirmation = "password", "password"
+    assert !u.save
+    assert_equal 'activerecord_error_taken', u.errors.on(:mail)
   end\r
 
   def test_update