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