]> projects.mako.cc - selectricity/blob - test/unit/user_test.rb
Created a user "summary/profile page". Also corected several minor typos on election...
[selectricity] / test / unit / user_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
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
7   fixtures :users
8
9   def test_should_create_user
10     assert_difference User, :count do
11       user = create_user
12       assert !user.new_record?, "#{user.errors.full_messages.to_sentence}"
13     end
14   end
15
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)
20     end
21   end
22
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)
27     end
28   end
29
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)
34     end
35   end
36
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)
41     end
42   end
43
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')
47   end
48
49   def test_should_not_rehash_password
50     users(:quentin).update_attributes(:login => 'quentin2')
51     assert_equal users(:quentin), User.authenticate('quentin2', 'test')
52   end
53
54   def test_should_authenticate_user
55     assert_equal users(:quentin), User.authenticate('quentin', 'test')
56   end
57
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
62   end
63
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
69   end
70
71   protected
72     def create_user(options = {})
73       User.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options))
74     end
75 end

Benjamin Mako Hill || Want to submit a patch?