change_password_test.rb
3.02 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
require File.dirname(__FILE__) + '/../test_helper'
class ChangePasswordTest < Test::Unit::TestCase
fixtures :environments
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
create_user('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
create_user('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
create_user('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 'require correct passsword confirmation' do
create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com')
change = ChangePassword.new
change.login = 'testuser'
change.email = 'test@example.com'
change.save!
change.status = Task::Status::FINISHED
change.password = 'right'
change.password_confirmation = 'wrong'
assert !change.valid?
assert change.errors.invalid?(:password)
change.password_confirmation = 'right'
assert change.valid?
end
should 'actually change password' do
User.destroy_all
person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com').person
change = ChangePassword.new
change.login = 'testuser'
change.email = 'test@example.com'
change.save!
change.expects(:requestor).returns(person).at_least_once
change.password = 'newpass'
change.password_confirmation = 'newpass'
change.finish
assert User.find(person.user.id).authenticated?('newpass')
end
should 'not require password and password confirmation when cancelling' do
User.destroy_all
person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com').person
change = ChangePassword.new
change.login = 'testuser'
change.email = 'test@example.com'
change.save!
assert_nothing_raised do
change.cancel
end
end
should 'has default permission' do
t1 = Task.new
t2 = ChangePassword.new
assert_equal t1.permission, t2.permission
end
end