##// END OF EJS Templates
Fixed a typo in Object daddy...
Eric Davis -
r2896:5f48256c20cc
parent child
Show More
@@ -1,30 +1,30
1 1 class User < Principal
2 generator_for :login, :method => :next_email
2 generator_for :login, :method => :next_login
3 3 generator_for :mail, :method => :next_email
4 4 generator_for :firstname, :method => :next_firstname
5 5 generator_for :lastname, :method => :next_lastname
6 6
7 7 def self.next_login
8 8 @gen_login ||= 'user1'
9 9 @gen_login.succ!
10 10 @gen_login
11 11 end
12 12
13 13 def self.next_email
14 14 @last_email ||= 'user1'
15 15 @last_email.succ!
16 16 "#{@last_email}@example.com"
17 17 end
18 18
19 19 def self.next_firstname
20 20 @last_firstname ||= 'Bob'
21 21 @last_firstname.succ!
22 22 @last_firstname
23 23 end
24 24
25 25 def self.next_lastname
26 26 @last_lastname ||= 'Doe'
27 27 @last_lastname.succ!
28 28 @last_lastname
29 29 end
30 30 end
@@ -1,223 +1,229
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class UserTest < ActiveSupport::TestCase
21 21 fixtures :users, :members, :projects, :roles, :member_roles
22 22
23 23 def setup
24 24 @admin = User.find(1)
25 25 @jsmith = User.find(2)
26 26 @dlopper = User.find(3)
27 27 end
28 28
29 test 'object_daddy creation' do
30 User.generate_with_protected!(:firstname => 'Testing connection')
31 User.generate_with_protected!(:firstname => 'Testing connection')
32 assert_equal 2, User.count(:all, :conditions => {:firstname => 'Testing connection'})
33 end
34
29 35 def test_truth
30 36 assert_kind_of User, @jsmith
31 37 end
32 38
33 39 def test_create
34 40 user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
35 41
36 42 user.login = "jsmith"
37 43 user.password, user.password_confirmation = "password", "password"
38 44 # login uniqueness
39 45 assert !user.save
40 46 assert_equal 1, user.errors.count
41 47
42 48 user.login = "newuser"
43 49 user.password, user.password_confirmation = "passwd", "password"
44 50 # password confirmation
45 51 assert !user.save
46 52 assert_equal 1, user.errors.count
47 53
48 54 user.password, user.password_confirmation = "password", "password"
49 55 assert user.save
50 56 end
51 57
52 58 def test_mail_uniqueness_should_not_be_case_sensitive
53 59 u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
54 60 u.login = 'newuser1'
55 61 u.password, u.password_confirmation = "password", "password"
56 62 assert u.save
57 63
58 64 u = User.new(:firstname => "new", :lastname => "user", :mail => "newUser@Somenet.foo")
59 65 u.login = 'newuser2'
60 66 u.password, u.password_confirmation = "password", "password"
61 67 assert !u.save
62 68 assert_equal I18n.translate('activerecord.errors.messages.taken'), u.errors.on(:mail)
63 69 end
64 70
65 71 def test_update
66 72 assert_equal "admin", @admin.login
67 73 @admin.login = "john"
68 74 assert @admin.save, @admin.errors.full_messages.join("; ")
69 75 @admin.reload
70 76 assert_equal "john", @admin.login
71 77 end
72 78
73 79 def test_destroy
74 80 User.find(2).destroy
75 81 assert_nil User.find_by_id(2)
76 82 assert Member.find_all_by_user_id(2).empty?
77 83 end
78 84
79 85 def test_validate
80 86 @admin.login = ""
81 87 assert !@admin.save
82 88 assert_equal 1, @admin.errors.count
83 89 end
84 90
85 91 def test_password
86 92 user = User.try_to_login("admin", "admin")
87 93 assert_kind_of User, user
88 94 assert_equal "admin", user.login
89 95 user.password = "hello"
90 96 assert user.save
91 97
92 98 user = User.try_to_login("admin", "hello")
93 99 assert_kind_of User, user
94 100 assert_equal "admin", user.login
95 101 assert_equal User.hash_password("hello"), user.hashed_password
96 102 end
97 103
98 104 def test_name_format
99 105 assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname)
100 106 Setting.user_format = :firstname_lastname
101 107 assert_equal 'John Smith', @jsmith.reload.name
102 108 Setting.user_format = :username
103 109 assert_equal 'jsmith', @jsmith.reload.name
104 110 end
105 111
106 112 def test_lock
107 113 user = User.try_to_login("jsmith", "jsmith")
108 114 assert_equal @jsmith, user
109 115
110 116 @jsmith.status = User::STATUS_LOCKED
111 117 assert @jsmith.save
112 118
113 119 user = User.try_to_login("jsmith", "jsmith")
114 120 assert_equal nil, user
115 121 end
116 122
117 123 def test_create_anonymous
118 124 AnonymousUser.delete_all
119 125 anon = User.anonymous
120 126 assert !anon.new_record?
121 127 assert_kind_of AnonymousUser, anon
122 128 end
123 129
124 130 def test_rss_key
125 131 assert_nil @jsmith.rss_token
126 132 key = @jsmith.rss_key
127 133 assert_equal 40, key.length
128 134
129 135 @jsmith.reload
130 136 assert_equal key, @jsmith.rss_key
131 137 end
132 138
133 139 def test_roles_for_project
134 140 # user with a role
135 141 roles = @jsmith.roles_for_project(Project.find(1))
136 142 assert_kind_of Role, roles.first
137 143 assert_equal "Manager", roles.first.name
138 144
139 145 # user with no role
140 146 assert_nil @dlopper.roles_for_project(Project.find(2)).detect {|role| role.member?}
141 147 end
142 148
143 149 def test_mail_notification_all
144 150 @jsmith.mail_notification = true
145 151 @jsmith.notified_project_ids = []
146 152 @jsmith.save
147 153 @jsmith.reload
148 154 assert @jsmith.projects.first.recipients.include?(@jsmith.mail)
149 155 end
150 156
151 157 def test_mail_notification_selected
152 158 @jsmith.mail_notification = false
153 159 @jsmith.notified_project_ids = [1]
154 160 @jsmith.save
155 161 @jsmith.reload
156 162 assert Project.find(1).recipients.include?(@jsmith.mail)
157 163 end
158 164
159 165 def test_mail_notification_none
160 166 @jsmith.mail_notification = false
161 167 @jsmith.notified_project_ids = []
162 168 @jsmith.save
163 169 @jsmith.reload
164 170 assert !@jsmith.projects.first.recipients.include?(@jsmith.mail)
165 171 end
166 172
167 173 def test_comments_sorting_preference
168 174 assert !@jsmith.wants_comments_in_reverse_order?
169 175 @jsmith.pref.comments_sorting = 'asc'
170 176 assert !@jsmith.wants_comments_in_reverse_order?
171 177 @jsmith.pref.comments_sorting = 'desc'
172 178 assert @jsmith.wants_comments_in_reverse_order?
173 179 end
174 180
175 181 def test_find_by_mail_should_be_case_insensitive
176 182 u = User.find_by_mail('JSmith@somenet.foo')
177 183 assert_not_nil u
178 184 assert_equal 'jsmith@somenet.foo', u.mail
179 185 end
180 186
181 187 def test_random_password
182 188 u = User.new
183 189 u.random_password
184 190 assert !u.password.blank?
185 191 assert !u.password_confirmation.blank?
186 192 end
187 193
188 194 if Object.const_defined?(:OpenID)
189 195
190 196 def test_setting_identity_url
191 197 normalized_open_id_url = 'http://example.com/'
192 198 u = User.new( :identity_url => 'http://example.com/' )
193 199 assert_equal normalized_open_id_url, u.identity_url
194 200 end
195 201
196 202 def test_setting_identity_url_without_trailing_slash
197 203 normalized_open_id_url = 'http://example.com/'
198 204 u = User.new( :identity_url => 'http://example.com' )
199 205 assert_equal normalized_open_id_url, u.identity_url
200 206 end
201 207
202 208 def test_setting_identity_url_without_protocol
203 209 normalized_open_id_url = 'http://example.com/'
204 210 u = User.new( :identity_url => 'example.com' )
205 211 assert_equal normalized_open_id_url, u.identity_url
206 212 end
207 213
208 214 def test_setting_blank_identity_url
209 215 u = User.new( :identity_url => 'example.com' )
210 216 u.identity_url = ''
211 217 assert u.identity_url.blank?
212 218 end
213 219
214 220 def test_setting_invalid_identity_url
215 221 u = User.new( :identity_url => 'this is not an openid url' )
216 222 assert u.identity_url.blank?
217 223 end
218 224
219 225 else
220 226 puts "Skipping openid tests."
221 227 end
222 228
223 229 end
General Comments 0
You need to be logged in to leave comments. Login now