From 212bf1e2bbe680261beb4e096a051f63471cc45f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 10 Jan 2009 11:29:35 +0000 Subject: [PATCH] Makes email adress uniqueness case-insensitive (#2473). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2253 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/user.rb | 2 +- test/unit/user_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 96923900e..0005c85d1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 319a1c2f4..e8500623a 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -47,6 +47,19 @@ class UserTest < Test::Unit::TestCase user.password, user.password_confirmation = "password", "password" assert user.save + 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 def test_update -- 2.39.5