Chris@1517
|
1 # Redmine - project management software
|
Chris@1517
|
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
|
Chris@1517
|
3 #
|
Chris@1517
|
4 # This program is free software; you can redistribute it and/or
|
Chris@1517
|
5 # modify it under the terms of the GNU General Public License
|
Chris@1517
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@1517
|
7 # of the License, or (at your option) any later version.
|
Chris@1517
|
8 #
|
Chris@1517
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@1517
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@1517
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@1517
|
12 # GNU General Public License for more details.
|
Chris@1517
|
13 #
|
Chris@1517
|
14 # You should have received a copy of the GNU General Public License
|
Chris@1517
|
15 # along with this program; if not, write to the Free Software
|
Chris@1517
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@1517
|
17
|
Chris@1517
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@1517
|
19
|
Chris@1517
|
20 class UsersControllerTest < ActionController::TestCase
|
Chris@1517
|
21 include Redmine::I18n
|
Chris@1517
|
22
|
Chris@1517
|
23 fixtures :users, :projects, :members, :member_roles, :roles,
|
Chris@1517
|
24 :custom_fields, :custom_values, :groups_users,
|
Chris@1517
|
25 :auth_sources
|
Chris@1517
|
26
|
Chris@1517
|
27 def setup
|
Chris@1517
|
28 User.current = nil
|
Chris@1517
|
29 @request.session[:user_id] = 1 # admin
|
Chris@1517
|
30 end
|
Chris@1517
|
31
|
Chris@1517
|
32 def test_index
|
Chris@1517
|
33 get :index
|
Chris@1517
|
34 assert_response :success
|
Chris@1517
|
35 assert_template 'index'
|
Chris@1517
|
36 assert_not_nil assigns(:users)
|
Chris@1517
|
37 # active users only
|
Chris@1517
|
38 assert_nil assigns(:users).detect {|u| !u.active?}
|
Chris@1517
|
39 end
|
Chris@1517
|
40
|
Chris@1517
|
41 def test_index_with_status_filter
|
Chris@1517
|
42 get :index, :status => 3
|
Chris@1517
|
43 assert_response :success
|
Chris@1517
|
44 assert_template 'index'
|
Chris@1517
|
45 assert_not_nil assigns(:users)
|
Chris@1517
|
46 assert_equal [3], assigns(:users).map(&:status).uniq
|
Chris@1517
|
47 end
|
Chris@1517
|
48
|
Chris@1517
|
49 def test_index_with_name_filter
|
Chris@1517
|
50 get :index, :name => 'john'
|
Chris@1517
|
51 assert_response :success
|
Chris@1517
|
52 assert_template 'index'
|
Chris@1517
|
53 users = assigns(:users)
|
Chris@1517
|
54 assert_not_nil users
|
Chris@1517
|
55 assert_equal 1, users.size
|
Chris@1517
|
56 assert_equal 'John', users.first.firstname
|
Chris@1517
|
57 end
|
Chris@1517
|
58
|
Chris@1517
|
59 def test_index_with_group_filter
|
Chris@1517
|
60 get :index, :group_id => '10'
|
Chris@1517
|
61 assert_response :success
|
Chris@1517
|
62 assert_template 'index'
|
Chris@1517
|
63 users = assigns(:users)
|
Chris@1517
|
64 assert users.any?
|
Chris@1517
|
65 assert_equal([], (users - Group.find(10).users))
|
Chris@1517
|
66 assert_select 'select[name=group_id]' do
|
Chris@1517
|
67 assert_select 'option[value=10][selected=selected]'
|
Chris@1517
|
68 end
|
Chris@1517
|
69 end
|
Chris@1517
|
70
|
Chris@1517
|
71 def test_show
|
Chris@1517
|
72 @request.session[:user_id] = nil
|
Chris@1517
|
73 get :show, :id => 2
|
Chris@1517
|
74 assert_response :success
|
Chris@1517
|
75 assert_template 'show'
|
Chris@1517
|
76 assert_not_nil assigns(:user)
|
Chris@1517
|
77
|
Chris@1517
|
78 assert_tag 'li', :content => /Phone number/
|
Chris@1517
|
79 end
|
Chris@1517
|
80
|
Chris@1517
|
81 def test_show_should_not_display_hidden_custom_fields
|
Chris@1517
|
82 @request.session[:user_id] = nil
|
Chris@1517
|
83 UserCustomField.find_by_name('Phone number').update_attribute :visible, false
|
Chris@1517
|
84 get :show, :id => 2
|
Chris@1517
|
85 assert_response :success
|
Chris@1517
|
86 assert_template 'show'
|
Chris@1517
|
87 assert_not_nil assigns(:user)
|
Chris@1517
|
88
|
Chris@1517
|
89 assert_no_tag 'li', :content => /Phone number/
|
Chris@1517
|
90 end
|
Chris@1517
|
91
|
Chris@1517
|
92 def test_show_should_not_fail_when_custom_values_are_nil
|
Chris@1517
|
93 user = User.find(2)
|
Chris@1517
|
94
|
Chris@1517
|
95 # Create a custom field to illustrate the issue
|
Chris@1517
|
96 custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
|
Chris@1517
|
97 custom_value = user.custom_values.build(:custom_field => custom_field).save!
|
Chris@1517
|
98
|
Chris@1517
|
99 get :show, :id => 2
|
Chris@1517
|
100 assert_response :success
|
Chris@1517
|
101 end
|
Chris@1517
|
102
|
Chris@1517
|
103 def test_show_inactive
|
Chris@1517
|
104 @request.session[:user_id] = nil
|
Chris@1517
|
105 get :show, :id => 5
|
Chris@1517
|
106 assert_response 404
|
Chris@1517
|
107 end
|
Chris@1517
|
108
|
Chris@1517
|
109 def test_show_should_not_reveal_users_with_no_visible_activity_or_project
|
Chris@1517
|
110 @request.session[:user_id] = nil
|
Chris@1517
|
111 get :show, :id => 9
|
Chris@1517
|
112 assert_response 404
|
Chris@1517
|
113 end
|
Chris@1517
|
114
|
Chris@1517
|
115 def test_show_inactive_by_admin
|
Chris@1517
|
116 @request.session[:user_id] = 1
|
Chris@1517
|
117 get :show, :id => 5
|
Chris@1517
|
118 assert_response 200
|
Chris@1517
|
119 assert_not_nil assigns(:user)
|
Chris@1517
|
120 end
|
Chris@1517
|
121
|
Chris@1517
|
122 def test_show_displays_memberships_based_on_project_visibility
|
Chris@1517
|
123 @request.session[:user_id] = 1
|
Chris@1517
|
124 get :show, :id => 2
|
Chris@1517
|
125 assert_response :success
|
Chris@1517
|
126 memberships = assigns(:memberships)
|
Chris@1517
|
127 assert_not_nil memberships
|
Chris@1517
|
128 project_ids = memberships.map(&:project_id)
|
Chris@1517
|
129 assert project_ids.include?(2) #private project admin can see
|
Chris@1517
|
130 end
|
Chris@1517
|
131
|
Chris@1517
|
132 def test_show_current_should_require_authentication
|
Chris@1517
|
133 @request.session[:user_id] = nil
|
Chris@1517
|
134 get :show, :id => 'current'
|
Chris@1517
|
135 assert_response 302
|
Chris@1517
|
136 end
|
Chris@1517
|
137
|
Chris@1517
|
138 def test_show_current
|
Chris@1517
|
139 @request.session[:user_id] = 2
|
Chris@1517
|
140 get :show, :id => 'current'
|
Chris@1517
|
141 assert_response :success
|
Chris@1517
|
142 assert_template 'show'
|
Chris@1517
|
143 assert_equal User.find(2), assigns(:user)
|
Chris@1517
|
144 end
|
Chris@1517
|
145
|
Chris@1517
|
146 def test_new
|
Chris@1517
|
147 get :new
|
Chris@1517
|
148 assert_response :success
|
Chris@1517
|
149 assert_template :new
|
Chris@1517
|
150 assert assigns(:user)
|
Chris@1517
|
151 end
|
Chris@1517
|
152
|
Chris@1517
|
153 def test_create
|
Chris@1517
|
154 Setting.bcc_recipients = '1'
|
Chris@1517
|
155
|
Chris@1517
|
156 assert_difference 'User.count' do
|
Chris@1517
|
157 assert_difference 'ActionMailer::Base.deliveries.size' do
|
Chris@1517
|
158 post :create,
|
Chris@1517
|
159 :user => {
|
Chris@1517
|
160 :firstname => 'John',
|
Chris@1517
|
161 :lastname => 'Doe',
|
Chris@1517
|
162 :login => 'jdoe',
|
Chris@1517
|
163 :password => 'secret123',
|
Chris@1517
|
164 :password_confirmation => 'secret123',
|
Chris@1517
|
165 :mail => 'jdoe@gmail.com',
|
Chris@1517
|
166 :mail_notification => 'none'
|
Chris@1517
|
167 },
|
Chris@1517
|
168 :send_information => '1'
|
Chris@1517
|
169 end
|
Chris@1517
|
170 end
|
Chris@1517
|
171
|
Chris@1517
|
172 user = User.order('id DESC').first
|
Chris@1517
|
173 assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id
|
Chris@1517
|
174
|
Chris@1517
|
175 assert_equal 'John', user.firstname
|
Chris@1517
|
176 assert_equal 'Doe', user.lastname
|
Chris@1517
|
177 assert_equal 'jdoe', user.login
|
Chris@1517
|
178 assert_equal 'jdoe@gmail.com', user.mail
|
Chris@1517
|
179 assert_equal 'none', user.mail_notification
|
Chris@1517
|
180 assert user.check_password?('secret123')
|
Chris@1517
|
181
|
Chris@1517
|
182 mail = ActionMailer::Base.deliveries.last
|
Chris@1517
|
183 assert_not_nil mail
|
Chris@1517
|
184 assert_equal [user.mail], mail.bcc
|
Chris@1517
|
185 assert_mail_body_match 'secret', mail
|
Chris@1517
|
186 end
|
Chris@1517
|
187
|
Chris@1517
|
188 def test_create_with_preferences
|
Chris@1517
|
189 assert_difference 'User.count' do
|
Chris@1517
|
190 post :create,
|
Chris@1517
|
191 :user => {
|
Chris@1517
|
192 :firstname => 'John',
|
Chris@1517
|
193 :lastname => 'Doe',
|
Chris@1517
|
194 :login => 'jdoe',
|
Chris@1517
|
195 :password => 'secret123',
|
Chris@1517
|
196 :password_confirmation => 'secret123',
|
Chris@1517
|
197 :mail => 'jdoe@gmail.com',
|
Chris@1517
|
198 :mail_notification => 'none'
|
Chris@1517
|
199 },
|
Chris@1517
|
200 :pref => {
|
Chris@1517
|
201 'hide_mail' => '1',
|
Chris@1517
|
202 'time_zone' => 'Paris',
|
Chris@1517
|
203 'comments_sorting' => 'desc',
|
Chris@1517
|
204 'warn_on_leaving_unsaved' => '0'
|
Chris@1517
|
205 }
|
Chris@1517
|
206 end
|
Chris@1517
|
207 user = User.order('id DESC').first
|
Chris@1517
|
208 assert_equal 'jdoe', user.login
|
Chris@1517
|
209 assert_equal true, user.pref.hide_mail
|
Chris@1517
|
210 assert_equal 'Paris', user.pref.time_zone
|
Chris@1517
|
211 assert_equal 'desc', user.pref[:comments_sorting]
|
Chris@1517
|
212 assert_equal '0', user.pref[:warn_on_leaving_unsaved]
|
Chris@1517
|
213 end
|
Chris@1517
|
214
|
Chris@1517
|
215 def test_create_with_generate_password_should_email_the_password
|
Chris@1517
|
216 assert_difference 'User.count' do
|
Chris@1517
|
217 post :create, :user => {
|
Chris@1517
|
218 :login => 'randompass',
|
Chris@1517
|
219 :firstname => 'Random',
|
Chris@1517
|
220 :lastname => 'Pass',
|
Chris@1517
|
221 :mail => 'randompass@example.net',
|
Chris@1517
|
222 :language => 'en',
|
Chris@1517
|
223 :generate_password => '1',
|
Chris@1517
|
224 :password => '',
|
Chris@1517
|
225 :password_confirmation => ''
|
Chris@1517
|
226 }, :send_information => 1
|
Chris@1517
|
227 end
|
Chris@1517
|
228 user = User.order('id DESC').first
|
Chris@1517
|
229 assert_equal 'randompass', user.login
|
Chris@1517
|
230
|
Chris@1517
|
231 mail = ActionMailer::Base.deliveries.last
|
Chris@1517
|
232 assert_not_nil mail
|
Chris@1517
|
233 m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/)
|
Chris@1517
|
234 assert m
|
Chris@1517
|
235 password = m[1]
|
Chris@1517
|
236 assert user.check_password?(password)
|
Chris@1517
|
237 end
|
Chris@1517
|
238
|
Chris@1517
|
239 def test_create_with_failure
|
Chris@1517
|
240 assert_no_difference 'User.count' do
|
Chris@1517
|
241 post :create, :user => {}
|
Chris@1517
|
242 end
|
Chris@1517
|
243 assert_response :success
|
Chris@1517
|
244 assert_template 'new'
|
Chris@1517
|
245 end
|
Chris@1517
|
246
|
Chris@1517
|
247 def test_create_with_failure_sould_preserve_preference
|
Chris@1517
|
248 assert_no_difference 'User.count' do
|
Chris@1517
|
249 post :create,
|
Chris@1517
|
250 :user => {},
|
Chris@1517
|
251 :pref => {
|
Chris@1517
|
252 'no_self_notified' => '1',
|
Chris@1517
|
253 'hide_mail' => '1',
|
Chris@1517
|
254 'time_zone' => 'Paris',
|
Chris@1517
|
255 'comments_sorting' => 'desc',
|
Chris@1517
|
256 'warn_on_leaving_unsaved' => '0'
|
Chris@1517
|
257 }
|
Chris@1517
|
258 end
|
Chris@1517
|
259 assert_response :success
|
Chris@1517
|
260 assert_template 'new'
|
Chris@1517
|
261
|
Chris@1517
|
262 assert_select 'select#pref_time_zone option[selected=selected]', :text => /Paris/
|
Chris@1517
|
263 assert_select 'input#pref_no_self_notified[value=1][checked=checked]'
|
Chris@1517
|
264 end
|
Chris@1517
|
265
|
Chris@1517
|
266 def test_edit
|
Chris@1517
|
267 get :edit, :id => 2
|
Chris@1517
|
268 assert_response :success
|
Chris@1517
|
269 assert_template 'edit'
|
Chris@1517
|
270 assert_equal User.find(2), assigns(:user)
|
Chris@1517
|
271 end
|
Chris@1517
|
272
|
Chris@1517
|
273 def test_update
|
Chris@1517
|
274 ActionMailer::Base.deliveries.clear
|
Chris@1517
|
275 put :update, :id => 2,
|
Chris@1517
|
276 :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'},
|
Chris@1517
|
277 :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
|
Chris@1517
|
278 user = User.find(2)
|
Chris@1517
|
279 assert_equal 'Changed', user.firstname
|
Chris@1517
|
280 assert_equal 'only_assigned', user.mail_notification
|
Chris@1517
|
281 assert_equal true, user.pref[:hide_mail]
|
Chris@1517
|
282 assert_equal 'desc', user.pref[:comments_sorting]
|
Chris@1517
|
283 assert ActionMailer::Base.deliveries.empty?
|
Chris@1517
|
284 end
|
Chris@1517
|
285
|
Chris@1517
|
286 def test_update_with_failure
|
Chris@1517
|
287 assert_no_difference 'User.count' do
|
Chris@1517
|
288 put :update, :id => 2, :user => {:firstname => ''}
|
Chris@1517
|
289 end
|
Chris@1517
|
290 assert_response :success
|
Chris@1517
|
291 assert_template 'edit'
|
Chris@1517
|
292 end
|
Chris@1517
|
293
|
Chris@1517
|
294 def test_update_with_group_ids_should_assign_groups
|
Chris@1517
|
295 put :update, :id => 2, :user => {:group_ids => ['10']}
|
Chris@1517
|
296 user = User.find(2)
|
Chris@1517
|
297 assert_equal [10], user.group_ids
|
Chris@1517
|
298 end
|
Chris@1517
|
299
|
Chris@1517
|
300 def test_update_with_activation_should_send_a_notification
|
Chris@1517
|
301 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
|
Chris@1517
|
302 u.login = 'foo'
|
Chris@1517
|
303 u.status = User::STATUS_REGISTERED
|
Chris@1517
|
304 u.save!
|
Chris@1517
|
305 ActionMailer::Base.deliveries.clear
|
Chris@1517
|
306 Setting.bcc_recipients = '1'
|
Chris@1517
|
307
|
Chris@1517
|
308 put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
|
Chris@1517
|
309 assert u.reload.active?
|
Chris@1517
|
310 mail = ActionMailer::Base.deliveries.last
|
Chris@1517
|
311 assert_not_nil mail
|
Chris@1517
|
312 assert_equal ['foo.bar@somenet.foo'], mail.bcc
|
Chris@1517
|
313 assert_mail_body_match ll('fr', :notice_account_activated), mail
|
Chris@1517
|
314 end
|
Chris@1517
|
315
|
Chris@1517
|
316 def test_update_with_password_change_should_send_a_notification
|
Chris@1517
|
317 ActionMailer::Base.deliveries.clear
|
Chris@1517
|
318 Setting.bcc_recipients = '1'
|
Chris@1517
|
319
|
Chris@1517
|
320 put :update, :id => 2, :user => {:password => 'newpass123', :password_confirmation => 'newpass123'}, :send_information => '1'
|
Chris@1517
|
321 u = User.find(2)
|
Chris@1517
|
322 assert u.check_password?('newpass123')
|
Chris@1517
|
323
|
Chris@1517
|
324 mail = ActionMailer::Base.deliveries.last
|
Chris@1517
|
325 assert_not_nil mail
|
Chris@1517
|
326 assert_equal [u.mail], mail.bcc
|
Chris@1517
|
327 assert_mail_body_match 'newpass123', mail
|
Chris@1517
|
328 end
|
Chris@1517
|
329
|
Chris@1517
|
330 def test_update_with_generate_password_should_email_the_password
|
Chris@1517
|
331 ActionMailer::Base.deliveries.clear
|
Chris@1517
|
332 Setting.bcc_recipients = '1'
|
Chris@1517
|
333
|
Chris@1517
|
334 put :update, :id => 2, :user => {
|
Chris@1517
|
335 :generate_password => '1',
|
Chris@1517
|
336 :password => '',
|
Chris@1517
|
337 :password_confirmation => ''
|
Chris@1517
|
338 }, :send_information => '1'
|
Chris@1517
|
339
|
Chris@1517
|
340 mail = ActionMailer::Base.deliveries.last
|
Chris@1517
|
341 assert_not_nil mail
|
Chris@1517
|
342 m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/)
|
Chris@1517
|
343 assert m
|
Chris@1517
|
344 password = m[1]
|
Chris@1517
|
345 assert User.find(2).check_password?(password)
|
Chris@1517
|
346 end
|
Chris@1517
|
347
|
Chris@1517
|
348 def test_update_without_generate_password_should_not_change_password
|
Chris@1517
|
349 put :update, :id => 2, :user => {
|
Chris@1517
|
350 :firstname => 'changed',
|
Chris@1517
|
351 :generate_password => '0',
|
Chris@1517
|
352 :password => '',
|
Chris@1517
|
353 :password_confirmation => ''
|
Chris@1517
|
354 }, :send_information => '1'
|
Chris@1517
|
355
|
Chris@1517
|
356 user = User.find(2)
|
Chris@1517
|
357 assert_equal 'changed', user.firstname
|
Chris@1517
|
358 assert user.check_password?('jsmith')
|
Chris@1517
|
359 end
|
Chris@1517
|
360
|
Chris@1517
|
361 def test_update_user_switchin_from_auth_source_to_password_authentication
|
Chris@1517
|
362 # Configure as auth source
|
Chris@1517
|
363 u = User.find(2)
|
Chris@1517
|
364 u.auth_source = AuthSource.find(1)
|
Chris@1517
|
365 u.save!
|
Chris@1517
|
366
|
Chris@1517
|
367 put :update, :id => u.id, :user => {:auth_source_id => '', :password => 'newpass123', :password_confirmation => 'newpass123'}
|
Chris@1517
|
368
|
Chris@1517
|
369 assert_equal nil, u.reload.auth_source
|
Chris@1517
|
370 assert u.check_password?('newpass123')
|
Chris@1517
|
371 end
|
Chris@1517
|
372
|
Chris@1517
|
373 def test_update_notified_project
|
Chris@1517
|
374 get :edit, :id => 2
|
Chris@1517
|
375 assert_response :success
|
Chris@1517
|
376 assert_template 'edit'
|
Chris@1517
|
377 u = User.find(2)
|
Chris@1517
|
378 assert_equal [1, 2, 5], u.projects.collect{|p| p.id}.sort
|
Chris@1517
|
379 assert_equal [1, 2, 5], u.notified_projects_ids.sort
|
Chris@1517
|
380 assert_select 'input[name=?][value=?]', 'user[notified_project_ids][]', '1'
|
Chris@1517
|
381 assert_equal 'all', u.mail_notification
|
Chris@1517
|
382 put :update, :id => 2,
|
Chris@1517
|
383 :user => {
|
Chris@1517
|
384 :mail_notification => 'selected',
|
Chris@1517
|
385 :notified_project_ids => [1, 2]
|
Chris@1517
|
386 }
|
Chris@1517
|
387 u = User.find(2)
|
Chris@1517
|
388 assert_equal 'selected', u.mail_notification
|
Chris@1517
|
389 assert_equal [1, 2], u.notified_projects_ids.sort
|
Chris@1517
|
390 end
|
Chris@1517
|
391
|
Chris@1517
|
392 def test_update_status_should_not_update_attributes
|
Chris@1517
|
393 user = User.find(2)
|
Chris@1517
|
394 user.pref[:no_self_notified] = '1'
|
Chris@1517
|
395 user.pref.save
|
Chris@1517
|
396
|
Chris@1517
|
397 put :update, :id => 2, :user => {:status => 3}
|
Chris@1517
|
398 assert_response 302
|
Chris@1517
|
399 user = User.find(2)
|
Chris@1517
|
400 assert_equal 3, user.status
|
Chris@1517
|
401 assert_equal '1', user.pref[:no_self_notified]
|
Chris@1517
|
402 end
|
Chris@1517
|
403
|
Chris@1517
|
404 def test_destroy
|
Chris@1517
|
405 assert_difference 'User.count', -1 do
|
Chris@1517
|
406 delete :destroy, :id => 2
|
Chris@1517
|
407 end
|
Chris@1517
|
408 assert_redirected_to '/users'
|
Chris@1517
|
409 assert_nil User.find_by_id(2)
|
Chris@1517
|
410 end
|
Chris@1517
|
411
|
Chris@1517
|
412 def test_destroy_should_be_denied_for_non_admin_users
|
Chris@1517
|
413 @request.session[:user_id] = 3
|
Chris@1517
|
414
|
Chris@1517
|
415 assert_no_difference 'User.count' do
|
Chris@1517
|
416 get :destroy, :id => 2
|
Chris@1517
|
417 end
|
Chris@1517
|
418 assert_response 403
|
Chris@1517
|
419 end
|
Chris@1517
|
420
|
Chris@1517
|
421 def test_destroy_should_redirect_to_back_url_param
|
Chris@1517
|
422 assert_difference 'User.count', -1 do
|
Chris@1517
|
423 delete :destroy, :id => 2, :back_url => '/users?name=foo'
|
Chris@1517
|
424 end
|
Chris@1517
|
425 assert_redirected_to '/users?name=foo'
|
Chris@1517
|
426 end
|
Chris@1517
|
427
|
Chris@1517
|
428 def test_create_membership
|
Chris@1517
|
429 assert_difference 'Member.count' do
|
Chris@1517
|
430 post :edit_membership, :id => 7, :membership => { :project_id => 3, :role_ids => [2]}
|
Chris@1517
|
431 end
|
Chris@1517
|
432 assert_redirected_to :action => 'edit', :id => '7', :tab => 'memberships'
|
Chris@1517
|
433 member = Member.order('id DESC').first
|
Chris@1517
|
434 assert_equal User.find(7), member.principal
|
Chris@1517
|
435 assert_equal [2], member.role_ids
|
Chris@1517
|
436 assert_equal 3, member.project_id
|
Chris@1517
|
437 end
|
Chris@1517
|
438
|
Chris@1517
|
439 def test_create_membership_js_format
|
Chris@1517
|
440 assert_difference 'Member.count' do
|
Chris@1517
|
441 post :edit_membership, :id => 7, :membership => {:project_id => 3, :role_ids => [2]}, :format => 'js'
|
Chris@1517
|
442 assert_response :success
|
Chris@1517
|
443 assert_template 'edit_membership'
|
Chris@1517
|
444 assert_equal 'text/javascript', response.content_type
|
Chris@1517
|
445 end
|
Chris@1517
|
446 member = Member.order('id DESC').first
|
Chris@1517
|
447 assert_equal User.find(7), member.principal
|
Chris@1517
|
448 assert_equal [2], member.role_ids
|
Chris@1517
|
449 assert_equal 3, member.project_id
|
Chris@1517
|
450 assert_include 'tab-content-memberships', response.body
|
Chris@1517
|
451 end
|
Chris@1517
|
452
|
Chris@1517
|
453 def test_create_membership_js_format_with_failure
|
Chris@1517
|
454 assert_no_difference 'Member.count' do
|
Chris@1517
|
455 post :edit_membership, :id => 7, :membership => {:project_id => 3}, :format => 'js'
|
Chris@1517
|
456 assert_response :success
|
Chris@1517
|
457 assert_template 'edit_membership'
|
Chris@1517
|
458 assert_equal 'text/javascript', response.content_type
|
Chris@1517
|
459 end
|
Chris@1517
|
460 assert_include 'alert', response.body, "Alert message not sent"
|
Chris@1517
|
461 assert_include 'Role can\\\'t be empty', response.body, "Error message not sent"
|
Chris@1517
|
462 end
|
Chris@1517
|
463
|
Chris@1517
|
464 def test_update_membership
|
Chris@1517
|
465 assert_no_difference 'Member.count' do
|
Chris@1517
|
466 put :edit_membership, :id => 2, :membership_id => 1, :membership => { :role_ids => [2]}
|
Chris@1517
|
467 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
|
Chris@1517
|
468 end
|
Chris@1517
|
469 assert_equal [2], Member.find(1).role_ids
|
Chris@1517
|
470 end
|
Chris@1517
|
471
|
Chris@1517
|
472 def test_update_membership_js_format
|
Chris@1517
|
473 assert_no_difference 'Member.count' do
|
Chris@1517
|
474 put :edit_membership, :id => 2, :membership_id => 1, :membership => {:role_ids => [2]}, :format => 'js'
|
Chris@1517
|
475 assert_response :success
|
Chris@1517
|
476 assert_template 'edit_membership'
|
Chris@1517
|
477 assert_equal 'text/javascript', response.content_type
|
Chris@1517
|
478 end
|
Chris@1517
|
479 assert_equal [2], Member.find(1).role_ids
|
Chris@1517
|
480 assert_include 'tab-content-memberships', response.body
|
Chris@1517
|
481 end
|
Chris@1517
|
482
|
Chris@1517
|
483 def test_destroy_membership
|
Chris@1517
|
484 assert_difference 'Member.count', -1 do
|
Chris@1517
|
485 delete :destroy_membership, :id => 2, :membership_id => 1
|
Chris@1517
|
486 end
|
Chris@1517
|
487 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
|
Chris@1517
|
488 assert_nil Member.find_by_id(1)
|
Chris@1517
|
489 end
|
Chris@1517
|
490
|
Chris@1517
|
491 def test_destroy_membership_js_format
|
Chris@1517
|
492 assert_difference 'Member.count', -1 do
|
Chris@1517
|
493 delete :destroy_membership, :id => 2, :membership_id => 1, :format => 'js'
|
Chris@1517
|
494 assert_response :success
|
Chris@1517
|
495 assert_template 'destroy_membership'
|
Chris@1517
|
496 assert_equal 'text/javascript', response.content_type
|
Chris@1517
|
497 end
|
Chris@1517
|
498 assert_nil Member.find_by_id(1)
|
Chris@1517
|
499 assert_include 'tab-content-memberships', response.body
|
Chris@1517
|
500 end
|
Chris@1517
|
501 end
|