change_password_test.rb
2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require File.dirname(__FILE__) + '/../test_helper'
class ChangePasswordTest < Test::Unit::TestCase
should 'validate' do
data = ChangePassword.new
assert !data.valid?
end
should 'refuse invalid username' do
User.destroy_all
data = ChangePassword.new
data.login = 'unexisting'
data.valid?
assert data.errors.invalid?(:login)
end
should 'require a valid username' do
User.destroy_all
User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com')
data = ChangePassword.new
data.login = 'testuser'
data.valid?
assert !data.errors.invalid?(:login)
end
should 'refuse incorrect e-mail address' do
User.destroy_all
User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com')
data = ChangePassword.new
data.login = 'testuser'
data.email = 'wrong@example.com'
data.valid?
assert !data.errors.invalid?(:login)
assert data.errors.invalid?(:email)
end
should 'require the correct e-mail address' do
User.destroy_all
User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com')
data = ChangePassword.new
data.login = 'testuser'
data.email = 'test@example.com'
data.valid?
assert !data.errors.invalid?(:login)
assert !data.errors.invalid?(:email)
end
should 'send a message with a URL so the user can enter the new password' do
User.destroy_all
User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com')
data = ChangePassword.new
data.login = 'testuser'
data.email = 'test@example.com'
data.save!
end
should 'actually change password' do
User.destroy_all
User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com')
change = ChangePassword.new
change.login = 'testuser'
change.email = 'test@example.com'
change.save!
user = User.new
user.expects(:force_change_password!).with('newpass', 'newpass')
User.expects(:find_by_login).with('testuser').returns(user)
change.password = 'newpass'
change.password_confirmation = 'newpass'
change.finish
end
end