##// END OF EJS Templates
fix UsersControllerTest failure randomly...
Toshi MARUYAMA -
r13501:e7346625f09f
parent child
Show More
@@ -1,449 +1,452
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 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.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class UsersControllerTest < ActionController::TestCase
20 class UsersControllerTest < ActionController::TestCase
21 include Redmine::I18n
21 include Redmine::I18n
22
22
23 fixtures :users, :projects, :members, :member_roles, :roles,
23 fixtures :users, :projects, :members, :member_roles, :roles,
24 :custom_fields, :custom_values, :groups_users,
24 :custom_fields, :custom_values, :groups_users,
25 :auth_sources
25 :auth_sources,
26 :enabled_modules,
27 :issues, :issue_statuses,
28 :trackers
26
29
27 def setup
30 def setup
28 User.current = nil
31 User.current = nil
29 @request.session[:user_id] = 1 # admin
32 @request.session[:user_id] = 1 # admin
30 end
33 end
31
34
32 def test_index
35 def test_index
33 get :index
36 get :index
34 assert_response :success
37 assert_response :success
35 assert_template 'index'
38 assert_template 'index'
36 assert_not_nil assigns(:users)
39 assert_not_nil assigns(:users)
37 # active users only
40 # active users only
38 assert_nil assigns(:users).detect {|u| !u.active?}
41 assert_nil assigns(:users).detect {|u| !u.active?}
39 end
42 end
40
43
41 def test_index_with_status_filter
44 def test_index_with_status_filter
42 get :index, :status => 3
45 get :index, :status => 3
43 assert_response :success
46 assert_response :success
44 assert_template 'index'
47 assert_template 'index'
45 assert_not_nil assigns(:users)
48 assert_not_nil assigns(:users)
46 assert_equal [3], assigns(:users).map(&:status).uniq
49 assert_equal [3], assigns(:users).map(&:status).uniq
47 end
50 end
48
51
49 def test_index_with_name_filter
52 def test_index_with_name_filter
50 get :index, :name => 'john'
53 get :index, :name => 'john'
51 assert_response :success
54 assert_response :success
52 assert_template 'index'
55 assert_template 'index'
53 users = assigns(:users)
56 users = assigns(:users)
54 assert_not_nil users
57 assert_not_nil users
55 assert_equal 1, users.size
58 assert_equal 1, users.size
56 assert_equal 'John', users.first.firstname
59 assert_equal 'John', users.first.firstname
57 end
60 end
58
61
59 def test_index_with_group_filter
62 def test_index_with_group_filter
60 get :index, :group_id => '10'
63 get :index, :group_id => '10'
61 assert_response :success
64 assert_response :success
62 assert_template 'index'
65 assert_template 'index'
63 users = assigns(:users)
66 users = assigns(:users)
64 assert users.any?
67 assert users.any?
65 assert_equal([], (users - Group.find(10).users))
68 assert_equal([], (users - Group.find(10).users))
66 assert_select 'select[name=group_id]' do
69 assert_select 'select[name=group_id]' do
67 assert_select 'option[value="10"][selected=selected]'
70 assert_select 'option[value="10"][selected=selected]'
68 end
71 end
69 end
72 end
70
73
71 def test_show
74 def test_show
72 @request.session[:user_id] = nil
75 @request.session[:user_id] = nil
73 get :show, :id => 2
76 get :show, :id => 2
74 assert_response :success
77 assert_response :success
75 assert_template 'show'
78 assert_template 'show'
76 assert_not_nil assigns(:user)
79 assert_not_nil assigns(:user)
77
80
78 assert_select 'li', :text => /Phone number/
81 assert_select 'li', :text => /Phone number/
79 end
82 end
80
83
81 def test_show_should_not_display_hidden_custom_fields
84 def test_show_should_not_display_hidden_custom_fields
82 @request.session[:user_id] = nil
85 @request.session[:user_id] = nil
83 UserCustomField.find_by_name('Phone number').update_attribute :visible, false
86 UserCustomField.find_by_name('Phone number').update_attribute :visible, false
84 get :show, :id => 2
87 get :show, :id => 2
85 assert_response :success
88 assert_response :success
86 assert_template 'show'
89 assert_template 'show'
87 assert_not_nil assigns(:user)
90 assert_not_nil assigns(:user)
88
91
89 assert_select 'li', :text => /Phone number/, :count => 0
92 assert_select 'li', :text => /Phone number/, :count => 0
90 end
93 end
91
94
92 def test_show_should_not_fail_when_custom_values_are_nil
95 def test_show_should_not_fail_when_custom_values_are_nil
93 user = User.find(2)
96 user = User.find(2)
94
97
95 # Create a custom field to illustrate the issue
98 # Create a custom field to illustrate the issue
96 custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
99 custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
97 custom_value = user.custom_values.build(:custom_field => custom_field).save!
100 custom_value = user.custom_values.build(:custom_field => custom_field).save!
98
101
99 get :show, :id => 2
102 get :show, :id => 2
100 assert_response :success
103 assert_response :success
101 end
104 end
102
105
103 def test_show_inactive
106 def test_show_inactive
104 @request.session[:user_id] = nil
107 @request.session[:user_id] = nil
105 get :show, :id => 5
108 get :show, :id => 5
106 assert_response 404
109 assert_response 404
107 end
110 end
108
111
109 def test_show_inactive_by_admin
112 def test_show_inactive_by_admin
110 @request.session[:user_id] = 1
113 @request.session[:user_id] = 1
111 get :show, :id => 5
114 get :show, :id => 5
112 assert_response 200
115 assert_response 200
113 assert_not_nil assigns(:user)
116 assert_not_nil assigns(:user)
114 end
117 end
115
118
116 def test_show_user_who_is_not_visible_should_return_404
119 def test_show_user_who_is_not_visible_should_return_404
117 Role.anonymous.update! :users_visibility => 'members_of_visible_projects'
120 Role.anonymous.update! :users_visibility => 'members_of_visible_projects'
118 user = User.generate!
121 user = User.generate!
119
122
120 @request.session[:user_id] = nil
123 @request.session[:user_id] = nil
121 get :show, :id => user.id
124 get :show, :id => user.id
122 assert_response 404
125 assert_response 404
123 end
126 end
124
127
125 def test_show_displays_memberships_based_on_project_visibility
128 def test_show_displays_memberships_based_on_project_visibility
126 @request.session[:user_id] = 1
129 @request.session[:user_id] = 1
127 get :show, :id => 2
130 get :show, :id => 2
128 assert_response :success
131 assert_response :success
129 memberships = assigns(:memberships)
132 memberships = assigns(:memberships)
130 assert_not_nil memberships
133 assert_not_nil memberships
131 project_ids = memberships.map(&:project_id)
134 project_ids = memberships.map(&:project_id)
132 assert project_ids.include?(2) #private project admin can see
135 assert project_ids.include?(2) #private project admin can see
133 end
136 end
134
137
135 def test_show_current_should_require_authentication
138 def test_show_current_should_require_authentication
136 @request.session[:user_id] = nil
139 @request.session[:user_id] = nil
137 get :show, :id => 'current'
140 get :show, :id => 'current'
138 assert_response 302
141 assert_response 302
139 end
142 end
140
143
141 def test_show_current
144 def test_show_current
142 @request.session[:user_id] = 2
145 @request.session[:user_id] = 2
143 get :show, :id => 'current'
146 get :show, :id => 'current'
144 assert_response :success
147 assert_response :success
145 assert_template 'show'
148 assert_template 'show'
146 assert_equal User.find(2), assigns(:user)
149 assert_equal User.find(2), assigns(:user)
147 end
150 end
148
151
149 def test_new
152 def test_new
150 get :new
153 get :new
151 assert_response :success
154 assert_response :success
152 assert_template :new
155 assert_template :new
153 assert assigns(:user)
156 assert assigns(:user)
154 end
157 end
155
158
156 def test_create
159 def test_create
157 Setting.bcc_recipients = '1'
160 Setting.bcc_recipients = '1'
158
161
159 assert_difference 'User.count' do
162 assert_difference 'User.count' do
160 assert_difference 'ActionMailer::Base.deliveries.size' do
163 assert_difference 'ActionMailer::Base.deliveries.size' do
161 post :create,
164 post :create,
162 :user => {
165 :user => {
163 :firstname => 'John',
166 :firstname => 'John',
164 :lastname => 'Doe',
167 :lastname => 'Doe',
165 :login => 'jdoe',
168 :login => 'jdoe',
166 :password => 'secret123',
169 :password => 'secret123',
167 :password_confirmation => 'secret123',
170 :password_confirmation => 'secret123',
168 :mail => 'jdoe@gmail.com',
171 :mail => 'jdoe@gmail.com',
169 :mail_notification => 'none'
172 :mail_notification => 'none'
170 },
173 },
171 :send_information => '1'
174 :send_information => '1'
172 end
175 end
173 end
176 end
174
177
175 user = User.order('id DESC').first
178 user = User.order('id DESC').first
176 assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id
179 assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id
177
180
178 assert_equal 'John', user.firstname
181 assert_equal 'John', user.firstname
179 assert_equal 'Doe', user.lastname
182 assert_equal 'Doe', user.lastname
180 assert_equal 'jdoe', user.login
183 assert_equal 'jdoe', user.login
181 assert_equal 'jdoe@gmail.com', user.mail
184 assert_equal 'jdoe@gmail.com', user.mail
182 assert_equal 'none', user.mail_notification
185 assert_equal 'none', user.mail_notification
183 assert user.check_password?('secret123')
186 assert user.check_password?('secret123')
184
187
185 mail = ActionMailer::Base.deliveries.last
188 mail = ActionMailer::Base.deliveries.last
186 assert_not_nil mail
189 assert_not_nil mail
187 assert_equal [user.mail], mail.bcc
190 assert_equal [user.mail], mail.bcc
188 assert_mail_body_match 'secret', mail
191 assert_mail_body_match 'secret', mail
189 end
192 end
190
193
191 def test_create_with_preferences
194 def test_create_with_preferences
192 assert_difference 'User.count' do
195 assert_difference 'User.count' do
193 post :create,
196 post :create,
194 :user => {
197 :user => {
195 :firstname => 'John',
198 :firstname => 'John',
196 :lastname => 'Doe',
199 :lastname => 'Doe',
197 :login => 'jdoe',
200 :login => 'jdoe',
198 :password => 'secret123',
201 :password => 'secret123',
199 :password_confirmation => 'secret123',
202 :password_confirmation => 'secret123',
200 :mail => 'jdoe@gmail.com',
203 :mail => 'jdoe@gmail.com',
201 :mail_notification => 'none'
204 :mail_notification => 'none'
202 },
205 },
203 :pref => {
206 :pref => {
204 'hide_mail' => '1',
207 'hide_mail' => '1',
205 'time_zone' => 'Paris',
208 'time_zone' => 'Paris',
206 'comments_sorting' => 'desc',
209 'comments_sorting' => 'desc',
207 'warn_on_leaving_unsaved' => '0'
210 'warn_on_leaving_unsaved' => '0'
208 }
211 }
209 end
212 end
210 user = User.order('id DESC').first
213 user = User.order('id DESC').first
211 assert_equal 'jdoe', user.login
214 assert_equal 'jdoe', user.login
212 assert_equal true, user.pref.hide_mail
215 assert_equal true, user.pref.hide_mail
213 assert_equal 'Paris', user.pref.time_zone
216 assert_equal 'Paris', user.pref.time_zone
214 assert_equal 'desc', user.pref[:comments_sorting]
217 assert_equal 'desc', user.pref[:comments_sorting]
215 assert_equal '0', user.pref[:warn_on_leaving_unsaved]
218 assert_equal '0', user.pref[:warn_on_leaving_unsaved]
216 end
219 end
217
220
218 def test_create_with_generate_password_should_email_the_password
221 def test_create_with_generate_password_should_email_the_password
219 assert_difference 'User.count' do
222 assert_difference 'User.count' do
220 post :create, :user => {
223 post :create, :user => {
221 :login => 'randompass',
224 :login => 'randompass',
222 :firstname => 'Random',
225 :firstname => 'Random',
223 :lastname => 'Pass',
226 :lastname => 'Pass',
224 :mail => 'randompass@example.net',
227 :mail => 'randompass@example.net',
225 :language => 'en',
228 :language => 'en',
226 :generate_password => '1',
229 :generate_password => '1',
227 :password => '',
230 :password => '',
228 :password_confirmation => ''
231 :password_confirmation => ''
229 }, :send_information => 1
232 }, :send_information => 1
230 end
233 end
231 user = User.order('id DESC').first
234 user = User.order('id DESC').first
232 assert_equal 'randompass', user.login
235 assert_equal 'randompass', user.login
233
236
234 mail = ActionMailer::Base.deliveries.last
237 mail = ActionMailer::Base.deliveries.last
235 assert_not_nil mail
238 assert_not_nil mail
236 m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/)
239 m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/)
237 assert m
240 assert m
238 password = m[1]
241 password = m[1]
239 assert user.check_password?(password)
242 assert user.check_password?(password)
240 end
243 end
241
244
242 def test_create_and_continue
245 def test_create_and_continue
243 post :create, :user => {
246 post :create, :user => {
244 :login => 'randompass',
247 :login => 'randompass',
245 :firstname => 'Random',
248 :firstname => 'Random',
246 :lastname => 'Pass',
249 :lastname => 'Pass',
247 :mail => 'randompass@example.net',
250 :mail => 'randompass@example.net',
248 :generate_password => '1'
251 :generate_password => '1'
249 }, :continue => '1'
252 }, :continue => '1'
250 assert_redirected_to '/users/new?user%5Bgenerate_password%5D=1'
253 assert_redirected_to '/users/new?user%5Bgenerate_password%5D=1'
251 end
254 end
252
255
253 def test_create_with_failure
256 def test_create_with_failure
254 assert_no_difference 'User.count' do
257 assert_no_difference 'User.count' do
255 post :create, :user => {}
258 post :create, :user => {}
256 end
259 end
257 assert_response :success
260 assert_response :success
258 assert_template 'new'
261 assert_template 'new'
259 end
262 end
260
263
261 def test_create_with_failure_sould_preserve_preference
264 def test_create_with_failure_sould_preserve_preference
262 assert_no_difference 'User.count' do
265 assert_no_difference 'User.count' do
263 post :create,
266 post :create,
264 :user => {},
267 :user => {},
265 :pref => {
268 :pref => {
266 'no_self_notified' => '1',
269 'no_self_notified' => '1',
267 'hide_mail' => '1',
270 'hide_mail' => '1',
268 'time_zone' => 'Paris',
271 'time_zone' => 'Paris',
269 'comments_sorting' => 'desc',
272 'comments_sorting' => 'desc',
270 'warn_on_leaving_unsaved' => '0'
273 'warn_on_leaving_unsaved' => '0'
271 }
274 }
272 end
275 end
273 assert_response :success
276 assert_response :success
274 assert_template 'new'
277 assert_template 'new'
275
278
276 assert_select 'select#pref_time_zone option[selected=selected]', :text => /Paris/
279 assert_select 'select#pref_time_zone option[selected=selected]', :text => /Paris/
277 assert_select 'input#pref_no_self_notified[value="1"][checked=checked]'
280 assert_select 'input#pref_no_self_notified[value="1"][checked=checked]'
278 end
281 end
279
282
280 def test_edit
283 def test_edit
281 get :edit, :id => 2
284 get :edit, :id => 2
282 assert_response :success
285 assert_response :success
283 assert_template 'edit'
286 assert_template 'edit'
284 assert_equal User.find(2), assigns(:user)
287 assert_equal User.find(2), assigns(:user)
285 end
288 end
286
289
287 def test_edit_registered_user
290 def test_edit_registered_user
288 assert User.find(2).register!
291 assert User.find(2).register!
289
292
290 get :edit, :id => 2
293 get :edit, :id => 2
291 assert_response :success
294 assert_response :success
292 assert_select 'a', :text => 'Activate'
295 assert_select 'a', :text => 'Activate'
293 end
296 end
294
297
295 def test_update
298 def test_update
296 ActionMailer::Base.deliveries.clear
299 ActionMailer::Base.deliveries.clear
297 put :update, :id => 2,
300 put :update, :id => 2,
298 :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'},
301 :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'},
299 :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
302 :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
300 user = User.find(2)
303 user = User.find(2)
301 assert_equal 'Changed', user.firstname
304 assert_equal 'Changed', user.firstname
302 assert_equal 'only_assigned', user.mail_notification
305 assert_equal 'only_assigned', user.mail_notification
303 assert_equal true, user.pref[:hide_mail]
306 assert_equal true, user.pref[:hide_mail]
304 assert_equal 'desc', user.pref[:comments_sorting]
307 assert_equal 'desc', user.pref[:comments_sorting]
305 assert ActionMailer::Base.deliveries.empty?
308 assert ActionMailer::Base.deliveries.empty?
306 end
309 end
307
310
308 def test_update_with_failure
311 def test_update_with_failure
309 assert_no_difference 'User.count' do
312 assert_no_difference 'User.count' do
310 put :update, :id => 2, :user => {:firstname => ''}
313 put :update, :id => 2, :user => {:firstname => ''}
311 end
314 end
312 assert_response :success
315 assert_response :success
313 assert_template 'edit'
316 assert_template 'edit'
314 end
317 end
315
318
316 def test_update_with_group_ids_should_assign_groups
319 def test_update_with_group_ids_should_assign_groups
317 put :update, :id => 2, :user => {:group_ids => ['10']}
320 put :update, :id => 2, :user => {:group_ids => ['10']}
318 user = User.find(2)
321 user = User.find(2)
319 assert_equal [10], user.group_ids
322 assert_equal [10], user.group_ids
320 end
323 end
321
324
322 def test_update_with_activation_should_send_a_notification
325 def test_update_with_activation_should_send_a_notification
323 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
326 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
324 u.login = 'foo'
327 u.login = 'foo'
325 u.status = User::STATUS_REGISTERED
328 u.status = User::STATUS_REGISTERED
326 u.save!
329 u.save!
327 ActionMailer::Base.deliveries.clear
330 ActionMailer::Base.deliveries.clear
328 Setting.bcc_recipients = '1'
331 Setting.bcc_recipients = '1'
329
332
330 put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
333 put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
331 assert u.reload.active?
334 assert u.reload.active?
332 mail = ActionMailer::Base.deliveries.last
335 mail = ActionMailer::Base.deliveries.last
333 assert_not_nil mail
336 assert_not_nil mail
334 assert_equal ['foo.bar@somenet.foo'], mail.bcc
337 assert_equal ['foo.bar@somenet.foo'], mail.bcc
335 assert_mail_body_match ll('fr', :notice_account_activated), mail
338 assert_mail_body_match ll('fr', :notice_account_activated), mail
336 end
339 end
337
340
338 def test_update_with_password_change_should_send_a_notification
341 def test_update_with_password_change_should_send_a_notification
339 ActionMailer::Base.deliveries.clear
342 ActionMailer::Base.deliveries.clear
340 Setting.bcc_recipients = '1'
343 Setting.bcc_recipients = '1'
341
344
342 put :update, :id => 2, :user => {:password => 'newpass123', :password_confirmation => 'newpass123'}, :send_information => '1'
345 put :update, :id => 2, :user => {:password => 'newpass123', :password_confirmation => 'newpass123'}, :send_information => '1'
343 u = User.find(2)
346 u = User.find(2)
344 assert u.check_password?('newpass123')
347 assert u.check_password?('newpass123')
345
348
346 mail = ActionMailer::Base.deliveries.last
349 mail = ActionMailer::Base.deliveries.last
347 assert_not_nil mail
350 assert_not_nil mail
348 assert_equal [u.mail], mail.bcc
351 assert_equal [u.mail], mail.bcc
349 assert_mail_body_match 'newpass123', mail
352 assert_mail_body_match 'newpass123', mail
350 end
353 end
351
354
352 def test_update_with_generate_password_should_email_the_password
355 def test_update_with_generate_password_should_email_the_password
353 ActionMailer::Base.deliveries.clear
356 ActionMailer::Base.deliveries.clear
354 Setting.bcc_recipients = '1'
357 Setting.bcc_recipients = '1'
355
358
356 put :update, :id => 2, :user => {
359 put :update, :id => 2, :user => {
357 :generate_password => '1',
360 :generate_password => '1',
358 :password => '',
361 :password => '',
359 :password_confirmation => ''
362 :password_confirmation => ''
360 }, :send_information => '1'
363 }, :send_information => '1'
361
364
362 mail = ActionMailer::Base.deliveries.last
365 mail = ActionMailer::Base.deliveries.last
363 assert_not_nil mail
366 assert_not_nil mail
364 m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/)
367 m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/)
365 assert m
368 assert m
366 password = m[1]
369 password = m[1]
367 assert User.find(2).check_password?(password)
370 assert User.find(2).check_password?(password)
368 end
371 end
369
372
370 def test_update_without_generate_password_should_not_change_password
373 def test_update_without_generate_password_should_not_change_password
371 put :update, :id => 2, :user => {
374 put :update, :id => 2, :user => {
372 :firstname => 'changed',
375 :firstname => 'changed',
373 :generate_password => '0',
376 :generate_password => '0',
374 :password => '',
377 :password => '',
375 :password_confirmation => ''
378 :password_confirmation => ''
376 }, :send_information => '1'
379 }, :send_information => '1'
377
380
378 user = User.find(2)
381 user = User.find(2)
379 assert_equal 'changed', user.firstname
382 assert_equal 'changed', user.firstname
380 assert user.check_password?('jsmith')
383 assert user.check_password?('jsmith')
381 end
384 end
382
385
383 def test_update_user_switchin_from_auth_source_to_password_authentication
386 def test_update_user_switchin_from_auth_source_to_password_authentication
384 # Configure as auth source
387 # Configure as auth source
385 u = User.find(2)
388 u = User.find(2)
386 u.auth_source = AuthSource.find(1)
389 u.auth_source = AuthSource.find(1)
387 u.save!
390 u.save!
388
391
389 put :update, :id => u.id, :user => {:auth_source_id => '', :password => 'newpass123', :password_confirmation => 'newpass123'}
392 put :update, :id => u.id, :user => {:auth_source_id => '', :password => 'newpass123', :password_confirmation => 'newpass123'}
390
393
391 assert_equal nil, u.reload.auth_source
394 assert_equal nil, u.reload.auth_source
392 assert u.check_password?('newpass123')
395 assert u.check_password?('newpass123')
393 end
396 end
394
397
395 def test_update_notified_project
398 def test_update_notified_project
396 get :edit, :id => 2
399 get :edit, :id => 2
397 assert_response :success
400 assert_response :success
398 assert_template 'edit'
401 assert_template 'edit'
399 u = User.find(2)
402 u = User.find(2)
400 assert_equal [1, 2, 5], u.projects.collect{|p| p.id}.sort
403 assert_equal [1, 2, 5], u.projects.collect{|p| p.id}.sort
401 assert_equal [1, 2, 5], u.notified_projects_ids.sort
404 assert_equal [1, 2, 5], u.notified_projects_ids.sort
402 assert_select 'input[name=?][value=?]', 'user[notified_project_ids][]', '1'
405 assert_select 'input[name=?][value=?]', 'user[notified_project_ids][]', '1'
403 assert_equal 'all', u.mail_notification
406 assert_equal 'all', u.mail_notification
404 put :update, :id => 2,
407 put :update, :id => 2,
405 :user => {
408 :user => {
406 :mail_notification => 'selected',
409 :mail_notification => 'selected',
407 :notified_project_ids => [1, 2]
410 :notified_project_ids => [1, 2]
408 }
411 }
409 u = User.find(2)
412 u = User.find(2)
410 assert_equal 'selected', u.mail_notification
413 assert_equal 'selected', u.mail_notification
411 assert_equal [1, 2], u.notified_projects_ids.sort
414 assert_equal [1, 2], u.notified_projects_ids.sort
412 end
415 end
413
416
414 def test_update_status_should_not_update_attributes
417 def test_update_status_should_not_update_attributes
415 user = User.find(2)
418 user = User.find(2)
416 user.pref[:no_self_notified] = '1'
419 user.pref[:no_self_notified] = '1'
417 user.pref.save
420 user.pref.save
418
421
419 put :update, :id => 2, :user => {:status => 3}
422 put :update, :id => 2, :user => {:status => 3}
420 assert_response 302
423 assert_response 302
421 user = User.find(2)
424 user = User.find(2)
422 assert_equal 3, user.status
425 assert_equal 3, user.status
423 assert_equal '1', user.pref[:no_self_notified]
426 assert_equal '1', user.pref[:no_self_notified]
424 end
427 end
425
428
426 def test_destroy
429 def test_destroy
427 assert_difference 'User.count', -1 do
430 assert_difference 'User.count', -1 do
428 delete :destroy, :id => 2
431 delete :destroy, :id => 2
429 end
432 end
430 assert_redirected_to '/users'
433 assert_redirected_to '/users'
431 assert_nil User.find_by_id(2)
434 assert_nil User.find_by_id(2)
432 end
435 end
433
436
434 def test_destroy_should_be_denied_for_non_admin_users
437 def test_destroy_should_be_denied_for_non_admin_users
435 @request.session[:user_id] = 3
438 @request.session[:user_id] = 3
436
439
437 assert_no_difference 'User.count' do
440 assert_no_difference 'User.count' do
438 get :destroy, :id => 2
441 get :destroy, :id => 2
439 end
442 end
440 assert_response 403
443 assert_response 403
441 end
444 end
442
445
443 def test_destroy_should_redirect_to_back_url_param
446 def test_destroy_should_redirect_to_back_url_param
444 assert_difference 'User.count', -1 do
447 assert_difference 'User.count', -1 do
445 delete :destroy, :id => 2, :back_url => '/users?name=foo'
448 delete :destroy, :id => 2, :back_url => '/users?name=foo'
446 end
449 end
447 assert_redirected_to '/users?name=foo'
450 assert_redirected_to '/users?name=foo'
448 end
451 end
449 end
452 end
General Comments 0
You need to be logged in to leave comments. Login now