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