]> source.dussan.org Git - redmine.git/commitdiff
Do not show 2 validation errors when user mail is blank.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 3 Jul 2011 12:37:57 +0000 (12:37 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 3 Jul 2011 12:37:57 +0000 (12:37 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6168 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index c06a907feef9eae7b2ed3e04a7a6a70158043dd1..1b7680182c14457f662aba45686ab58e202366d2 100644 (file)
@@ -69,7 +69,7 @@ class User < Principal
   validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i
   validates_length_of :login, :maximum => 30
   validates_length_of :firstname, :lastname, :maximum => 30
-  validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true
+  validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_blank => true
   validates_length_of :mail, :maximum => 60, :allow_nil => true
   validates_confirmation_of :password, :allow_nil => true
   validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true
index 3848eab0f128eb4b1760c0188316d7224355f213..0fbb7d0c93ab58736ef904a0f5175e84bb496fb9 100644 (file)
@@ -41,6 +41,13 @@ class UserTest < ActiveSupport::TestCase
     u.mail = " foo@bar.com  "
     assert_equal "foo@bar.com", u.mail
   end
+  
+  def test_mail_validation
+    u = User.new
+    u.mail = ''
+    assert !u.valid?
+    assert_equal I18n.translate('activerecord.errors.messages.blank'), u.errors.on(:mail)
+  end
 
   def test_create
     user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")