1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserTest < Test::Unit::TestCase
6 # Replace this with your real tests.
8 assert users(:aaron).display_name != users(:aaron).login
9 assert_equal "sam", users(:sam).display_name
10 # login overrules display_name when it is not present
11 users(:aaron).update_attributes :display_name => ''
12 assert_equal users(:aaron).login, users(:aaron).display_name
13 users(:aaron).update_attributes :display_name => nil
14 assert_equal users(:aaron).login, users(:aaron).display_name
17 def test_no_stupid_logins
19 %w(bob max123 imthemanbetyoucanttouchme tj_supaman).each do |login|
24 ['007', '1234556789', 'f451', "sam'er", "samm-ie", "<script>alert('im in ur base, killin ur d00ds')</script>"].each do |login|
30 def test_email_address_validation
34 u.email = "johh.doe@google.com"
36 u.email = "johh_doe@mail.mx.1.google.com"
38 u.email = "johh_doe+crazy-iness@mail.mx.1.google.com"
40 u.email = "sam@@colgate.com"
44 def test_minimum_password_length
46 u.password = "bluegill"
48 u.password = "fishing"
52 # fewer than 5 chars are not valid passwords
59 def test_no_valid_display_names
61 u.display_name="1234556789"
66 u.display_name="Josh Goebel"
68 u.display_name="Josh E. Goebel"
70 u.display_name="Zeph'er Cochran"
75 def test_first_user_becomes_admin
77 u=User.create(:email => "bob@aol.com", :password => "zoegirl", :password_confirmation => "zoegirl")
82 u=User.create(:email => "woody@aol.com", :password => "zoegirl", :password_confirmation => "zoegirl")
89 assert_nil users(:aaron).login_key
90 assert_nil users(:aaron).login_key_expires_at
91 users(:aaron).reset_login_key!
92 assert_equal 40, users(:aaron).login_key.length
93 assert users(:aaron).login_key_expires_at < Time.now.utc+1.year+1.minute
94 assert users(:aaron).login_key_expires_at > Time.now.utc+1.year-1.minute
97 def test_open_id_login
98 u = User.new(:openid_url => 'http://foo', :email => 'zoe@girl.com')