Class: UserTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
AuthenticatedTestHelper
Defined in:
vendor/plugins/authentication/test/unit/user_test.rb

Instance Method Summary collapse

Methods included from AuthenticatedTestHelper

#authorize_as, #login_as

Instance Method Details

#test_should_authenticate_userObject



67
68
69
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 67

def test_should_authenticate_user
  assert_equal users(:quentin), User.authenticate('quentin', 'test')
end

#test_should_create_and_start_in_pending_stateObject



22
23
24
25
26
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 22

def test_should_create_and_start_in_pending_state
  user = create_user
  user.reload
  assert user.pending?
end

#test_should_create_userObject



9
10
11
12
13
14
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 9

def test_should_create_user
  assert_difference 'User.count' do
    user = create_user
    assert !user.new_record?, "#{user.errors.full_messages.to_sentence}"
  end
end

#test_should_delete_userObject



151
152
153
154
155
156
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 151

def test_should_delete_user
  assert_nil users(:quentin).deleted_at
  users(:quentin).delete!
  assert_not_nil users(:quentin).deleted_at
  assert users(:quentin).deleted?
end

#test_should_initialize_activation_code_upon_creationObject



16
17
18
19
20
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 16

def test_should_initialize_activation_code_upon_creation
  user = create_user
  user.reload
  assert_not_nil user.activation_code
end

#test_should_not_rehash_passwordObject



62
63
64
65
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 62

def test_should_not_rehash_password
  users(:quentin).update_attributes(:login => 'quentin2')
  assert_equal users(:quentin), User.authenticate('quentin2', 'test')
end

#test_should_register_passive_userObject



110
111
112
113
114
115
116
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 110

def test_should_register_passive_user
  user = create_user(:password => nil, :password_confirmation => nil)
  assert user.passive?
  user.update_attributes(:password => 'new password', :password_confirmation => 'new password')
  user.register!
  assert user.pending?
end

#test_should_remember_me_default_two_weeksObject



101
102
103
104
105
106
107
108
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 101

def test_should_remember_me_default_two_weeks
  before = 2.weeks.from_now.utc
  users(:quentin).remember_me
  after = 2.weeks.from_now.utc
  assert_not_nil users(:quentin).remember_token
  assert_not_nil users(:quentin).remember_token_expires_at
  assert users(:quentin).remember_token_expires_at.between?(before, after)
end

#test_should_remember_me_for_one_weekObject



84
85
86
87
88
89
90
91
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 84

def test_should_remember_me_for_one_week
  before = 1.week.from_now.utc
  users(:quentin).remember_me_for 1.week
  after = 1.week.from_now.utc
  assert_not_nil users(:quentin).remember_token
  assert_not_nil users(:quentin).remember_token_expires_at
  assert users(:quentin).remember_token_expires_at.between?(before, after)
end

#test_should_remember_me_until_one_weekObject



93
94
95
96
97
98
99
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 93

def test_should_remember_me_until_one_week
  time = 1.week.from_now.utc
  users(:quentin).remember_me_until time
  assert_not_nil users(:quentin).remember_token
  assert_not_nil users(:quentin).remember_token_expires_at
  assert_equal users(:quentin).remember_token_expires_at, time
end

#test_should_require_emailObject



50
51
52
53
54
55
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 50

def test_should_require_email
  assert_no_difference 'User.count' do
    u = create_user(:email => nil)
    assert u.errors.on(:email)
  end
end

#test_should_require_loginObject



29
30
31
32
33
34
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 29

def 
  assert_no_difference 'User.count' do
    u = create_user(:login => nil)
    assert u.errors.on(:login)
  end
end

#test_should_require_passwordObject



36
37
38
39
40
41
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 36

def test_should_require_password
  assert_no_difference 'User.count' do
    u = create_user(:password => nil)
    assert u.errors.on(:password)
  end
end

#test_should_require_password_confirmationObject



43
44
45
46
47
48
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 43

def test_should_require_password_confirmation
  assert_no_difference 'User.count' do
    u = create_user(:password_confirmation => nil)
    assert u.errors.on(:password_confirmation)
  end
end

#test_should_reset_passwordObject



57
58
59
60
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 57

def test_should_reset_password
  users(:quentin).update_attributes(:password => 'new password', :password_confirmation => 'new password')
  assert_equal users(:quentin), User.authenticate('quentin', 'new password')
end

#test_should_set_remember_tokenObject



71
72
73
74
75
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 71

def test_should_set_remember_token
  users(:quentin).remember_me
  assert_not_nil users(:quentin).remember_token
  assert_not_nil users(:quentin).remember_token_expires_at
end

#test_should_suspend_userObject



118
119
120
121
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 118

def test_should_suspend_user
  users(:quentin).suspend!
  assert users(:quentin).suspended?
end

#test_should_unset_remember_tokenObject



77
78
79
80
81
82
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 77

def test_should_unset_remember_token
  users(:quentin).remember_me
  assert_not_nil users(:quentin).remember_token
  users(:quentin).forget_me
  assert_nil users(:quentin).remember_token
end

#test_should_unsuspend_user_to_active_stateObject



128
129
130
131
132
133
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 128

def test_should_unsuspend_user_to_active_state
  users(:quentin).suspend!
  assert users(:quentin).suspended?
  users(:quentin).unsuspend!
  assert users(:quentin).active?
end

#test_should_unsuspend_user_with_activation_code_and_nil_activated_at_to_pending_stateObject



143
144
145
146
147
148
149
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 143

def test_should_unsuspend_user_with_activation_code_and_nil_activated_at_to_pending_state
  users(:quentin).suspend!
  User.update_all :activation_code => 'foo-bar', :activated_at => nil
  assert users(:quentin).suspended?
  users(:quentin).reload.unsuspend!
  assert users(:quentin).pending?
end

#test_should_unsuspend_user_with_nil_activation_code_and_activated_at_to_passive_stateObject



135
136
137
138
139
140
141
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 135

def test_should_unsuspend_user_with_nil_activation_code_and_activated_at_to_passive_state
  users(:quentin).suspend!
  User.update_all :activation_code => nil, :activated_at => nil
  assert users(:quentin).suspended?
  users(:quentin).reload.unsuspend!
  assert users(:quentin).passive?
end

#test_suspended_user_should_not_authenticateObject



123
124
125
126
# File 'vendor/plugins/authentication/test/unit/user_test.rb', line 123

def test_suspended_user_should_not_authenticate
  users(:quentin).suspend!
  assert_not_equal users(:quentin), User.authenticate('quentin', 'test')
end