fixed user uname validation

This commit is contained in:
Alexander Machehin 2012-11-07 15:30:34 +06:00
parent 0d893c4b20
commit 36ac66303a
2 changed files with 8 additions and 2 deletions

View File

@ -29,7 +29,7 @@ class User < Avatar
has_many :key_pairs
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => {:with => /^[a-z0-9_]+$/}, :reserved_name => true
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => {:with => /\A[a-z0-9_]+\Z/}, :reserved_name => true
validate { errors.add(:uname, :taken) if Group.by_uname(uname).present? }
validates :role, :inclusion => {:in => ROLES}, :allow_blank => true
validates :language, :inclusion => {:in => LANGUAGES}, :allow_blank => true

View File

@ -92,4 +92,10 @@ describe User do
end
end
context "User creating" do
it "'hacked' uname should not pass" do
lambda {User.create! :uname => "new_user\nhacked!", :email => 'new_user@hacker.mm',
:password => '123456'}.should raise_error(ActiveRecord::RecordInvalid)
end
end
end