Permalink
Browse files

Deleted the trailing spaces on mail before validation

  • Loading branch information...
1 parent 4fef8b6 commit 98d20d1a1a71ee78e37798ade39980acd1da3dd2 Carin Meier committed Jul 22, 2010
Showing with 24 additions and 0 deletions.
  1. +9 −0 app/models/user.rb
  2. +15 −0 test/unit/user_test.rb
View
@@ -73,6 +73,15 @@ def before_save
# update hashed_password if password was set
self.hashed_password = User.hash_password(self.password) if self.password && self.auth_source_id.blank?
end
+
+ def before_validation
+ strip_mail_blanks
+ end
+
+ #strip trailing spaces from mail
+ def strip_mail_blanks
+ self.mail = self.mail.to_s.strip
+ end
def reload(*args)
@name = nil
View
@@ -83,6 +83,21 @@ def test_mail_uniqueness_should_not_be_case_sensitive
assert_equal I18n.translate('activerecord.errors.messages.taken'), u.errors.on(:mail)
end
+
+ def test_mail_should_chop_trailing_spaces
+ u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo ")
+ u.login = 'newuser'
+ u.password, u.password_confirmation = "password", "password"
+ assert u.save
+
+ #does not chop leading spaces
+ u = User.new(:firstname => "new", :lastname => "user", :mail => " newuser@somenet.foo ")
+ u.login = 'newuser'
+ u.password, u.password_confirmation = "password", "password"
+ assert !u.save
+
+ end
+
def test_update
assert_equal "admin", @admin.login
@admin.login = "john"

1 comment on commit 98d20d1

Owner

gigasquid commented on 98d20d1 Jul 22, 2010

This is for redmine issue http://www.redmine.org/issues/5834

Please sign in to comment.