Skip to content

Commit

Permalink
No @s in usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
steveklabnik committed Mar 29, 2011
1 parent a9d66f7 commit 80faec9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class User

# Make the username required
# However, this will break it when email authorization is used
key :username, String #, :unique => true
key :username, String #:unique => true
key :perishable_token, String

key :email, String #, :unique => true, :allow_nil => true
Expand All @@ -15,6 +15,9 @@ class User
validates_uniqueness_of :email, :allow_nil => :true
validates_uniqueness_of :username, :allow_nil => :true

# validate users don't have @ in their usernames
validate :no_at

belongs_to :author
belongs_to :feed

Expand Down Expand Up @@ -213,4 +216,11 @@ def follow_yo_self
followers << feed
save
end

# validation that checks @s in usernames
def no_at
unless (username =~ /@/).nil?
errors.add(:username, "can't have @.")
end
end
end
5 changes: 5 additions & 0 deletions test/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ def test_reset_password
assert u.hashed_password != prev_pass
end

def test_no_at_in_usernames
u = User.new :username => "[email protected]"
refute u.save, "@ in username"
end

end

0 comments on commit 80faec9

Please sign in to comment.