From 80faec94d3416be6e71908b218e062fca5ec377b Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 29 Mar 2011 17:39:12 -0400 Subject: [PATCH] No @s in usernames --- models/user.rb | 12 +++++++++++- test/user_test.rb | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/models/user.rb b/models/user.rb index 0955cc93..a1c0b52b 100644 --- a/models/user.rb +++ b/models/user.rb @@ -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 @@ -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 @@ -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 diff --git a/test/user_test.rb b/test/user_test.rb index e3efd4e5..377db6b8 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -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 => "someone@something.com" + refute u.save, "@ in username" + end + end