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