1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserTest < Test::Unit::TestCase
4 # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead.
5 # Then, you can remove it from this and the functional test.
6 include AuthenticatedTestHelper
9 def test_should_create_user
10 assert_difference User, :count do
12 assert !user.new_record?, "#{user.errors.full_messages.to_sentence}"
16 def test_should_require_login
17 assert_no_difference User, :count do
18 u = create_user(:login => nil)
19 assert u.errors.on(:login)
23 def test_should_require_password
24 assert_no_difference User, :count do
25 u = create_user(:password => nil)
26 assert u.errors.on(:password)
30 def test_should_require_password_confirmation
31 assert_no_difference User, :count do
32 u = create_user(:password_confirmation => nil)
33 assert u.errors.on(:password_confirmation)
37 def test_should_require_email
38 assert_no_difference User, :count do
39 u = create_user(:email => nil)
40 assert u.errors.on(:email)
44 def test_should_reset_password
45 users(:quentin).update_attributes(:password => 'new password', :password_confirmation => 'new password')
46 assert_equal users(:quentin), User.authenticate('quentin', 'new password')
49 def test_should_not_rehash_password
50 users(:quentin).update_attributes(:login => 'quentin2')
51 assert_equal users(:quentin), User.authenticate('quentin2', 'test')
54 def test_should_authenticate_user
55 assert_equal users(:quentin), User.authenticate('quentin', 'test')
58 def test_should_set_remember_token
59 users(:quentin).remember_me
60 assert_not_nil users(:quentin).remember_token
61 assert_not_nil users(:quentin).remember_token_expires_at
64 def test_should_unset_remember_token
65 users(:quentin).remember_me
66 assert_not_nil users(:quentin).remember_token
67 users(:quentin).forget_me
68 assert_nil users(:quentin).remember_token
72 def create_user(options = {})
73 User.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options))