@@ -5,12 +5,12 | |||||
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. | |
@@ -23,9 +23,9 class UsersController; def rescue_action(e) raise e end; end | |||||
23 |
|
23 | |||
24 | class UsersControllerTest < ActionController::TestCase |
|
24 | class UsersControllerTest < ActionController::TestCase | |
25 | include Redmine::I18n |
|
25 | include Redmine::I18n | |
26 |
|
26 | |||
27 | fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values, :groups_users |
|
27 | fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values, :groups_users | |
28 |
|
28 | |||
29 | def setup |
|
29 | def setup | |
30 | @controller = UsersController.new |
|
30 | @controller = UsersController.new | |
31 | @request = ActionController::TestRequest.new |
|
31 | @request = ActionController::TestRequest.new | |
@@ -33,7 +33,7 class UsersControllerTest < ActionController::TestCase | |||||
33 | User.current = nil |
|
33 | User.current = nil | |
34 | @request.session[:user_id] = 1 # admin |
|
34 | @request.session[:user_id] = 1 # admin | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | def test_index |
|
37 | def test_index | |
38 | get :index |
|
38 | get :index | |
39 | assert_response :success |
|
39 | assert_response :success | |
@@ -48,7 +48,7 class UsersControllerTest < ActionController::TestCase | |||||
48 | # active users only |
|
48 | # active users only | |
49 | assert_nil assigns(:users).detect {|u| !u.active?} |
|
49 | assert_nil assigns(:users).detect {|u| !u.active?} | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_index_with_name_filter |
|
52 | def test_index_with_name_filter | |
53 | get :index, :name => 'john' |
|
53 | get :index, :name => 'john' | |
54 | assert_response :success |
|
54 | assert_response :success | |
@@ -58,7 +58,7 class UsersControllerTest < ActionController::TestCase | |||||
58 | assert_equal 1, users.size |
|
58 | assert_equal 1, users.size | |
59 | assert_equal 'John', users.first.firstname |
|
59 | assert_equal 'John', users.first.firstname | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | def test_index_with_group_filter |
|
62 | def test_index_with_group_filter | |
63 | get :index, :group_id => '10' |
|
63 | get :index, :group_id => '10' | |
64 | assert_response :success |
|
64 | assert_response :success | |
@@ -67,17 +67,17 class UsersControllerTest < ActionController::TestCase | |||||
67 | assert users.any? |
|
67 | assert users.any? | |
68 | assert_equal([], (users - Group.find(10).users)) |
|
68 | assert_equal([], (users - Group.find(10).users)) | |
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 | |
@@ -85,7 +85,7 class UsersControllerTest < ActionController::TestCase | |||||
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 | |||
@@ -105,20 +105,20 class UsersControllerTest < ActionController::TestCase | |||||
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 | |
@@ -128,13 +128,13 class UsersControllerTest < ActionController::TestCase | |||||
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' | |
@@ -142,18 +142,18 class UsersControllerTest < ActionController::TestCase | |||||
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 |
|
148 | |||
149 | assert_response :success |
|
149 | assert_response :success | |
150 | assert_template :new |
|
150 | assert_template :new | |
151 | assert assigns(:user) |
|
151 | assert assigns(:user) | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | def test_create |
|
154 | def test_create | |
155 | Setting.bcc_recipients = '1' |
|
155 | Setting.bcc_recipients = '1' | |
156 |
|
156 | |||
157 | assert_difference 'User.count' do |
|
157 | assert_difference 'User.count' do | |
158 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
158 | assert_difference 'ActionMailer::Base.deliveries.size' do | |
159 | post :create, |
|
159 | post :create, | |
@@ -169,35 +169,35 class UsersControllerTest < ActionController::TestCase | |||||
169 | :send_information => '1' |
|
169 | :send_information => '1' | |
170 | end |
|
170 | end | |
171 | end |
|
171 | end | |
172 |
|
172 | |||
173 | user = User.first(:order => 'id DESC') |
|
173 | user = User.first(:order => 'id DESC') | |
174 | assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id |
|
174 | assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id | |
175 |
|
175 | |||
176 | assert_equal 'John', user.firstname |
|
176 | assert_equal 'John', user.firstname | |
177 | assert_equal 'Doe', user.lastname |
|
177 | assert_equal 'Doe', user.lastname | |
178 | assert_equal 'jdoe', user.login |
|
178 | assert_equal 'jdoe', user.login | |
179 | assert_equal 'jdoe@gmail.com', user.mail |
|
179 | assert_equal 'jdoe@gmail.com', user.mail | |
180 | assert_equal 'none', user.mail_notification |
|
180 | assert_equal 'none', user.mail_notification | |
181 | assert user.check_password?('secret') |
|
181 | assert user.check_password?('secret') | |
182 |
|
182 | |||
183 | mail = ActionMailer::Base.deliveries.last |
|
183 | mail = ActionMailer::Base.deliveries.last | |
184 | assert_not_nil mail |
|
184 | assert_not_nil mail | |
185 | assert_equal [user.mail], mail.bcc |
|
185 | assert_equal [user.mail], mail.bcc | |
186 | assert mail.body.include?('secret') |
|
186 | assert mail.body.include?('secret') | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | def test_create_with_failure |
|
189 | def test_create_with_failure | |
190 | assert_no_difference 'User.count' do |
|
190 | assert_no_difference 'User.count' do | |
191 | post :create, :user => {} |
|
191 | post :create, :user => {} | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
194 | assert_response :success |
|
194 | assert_response :success | |
195 | assert_template 'new' |
|
195 | assert_template 'new' | |
196 | end |
|
196 | end | |
197 |
|
197 | |||
198 | def test_edit |
|
198 | def test_edit | |
199 | get :edit, :id => 2 |
|
199 | get :edit, :id => 2 | |
200 |
|
200 | |||
201 | assert_response :success |
|
201 | assert_response :success | |
202 | assert_template 'edit' |
|
202 | assert_template 'edit' | |
203 | assert_equal User.find(2), assigns(:user) |
|
203 | assert_equal User.find(2), assigns(:user) | |
@@ -219,18 +219,18 class UsersControllerTest < ActionController::TestCase | |||||
219 | assert_no_difference 'User.count' do |
|
219 | assert_no_difference 'User.count' do | |
220 | put :update, :id => 2, :user => {:firstname => ''} |
|
220 | put :update, :id => 2, :user => {:firstname => ''} | |
221 | end |
|
221 | end | |
222 |
|
222 | |||
223 | assert_response :success |
|
223 | assert_response :success | |
224 | assert_template 'edit' |
|
224 | assert_template 'edit' | |
225 | end |
|
225 | end | |
226 |
|
226 | |||
227 | def test_update_with_group_ids_should_assign_groups |
|
227 | def test_update_with_group_ids_should_assign_groups | |
228 | put :update, :id => 2, :user => {:group_ids => ['10']} |
|
228 | put :update, :id => 2, :user => {:group_ids => ['10']} | |
229 |
|
229 | |||
230 | user = User.find(2) |
|
230 | user = User.find(2) | |
231 | assert_equal [10], user.group_ids |
|
231 | assert_equal [10], user.group_ids | |
232 | end |
|
232 | end | |
233 |
|
233 | |||
234 | def test_update_with_activation_should_send_a_notification |
|
234 | def test_update_with_activation_should_send_a_notification | |
235 | u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') |
|
235 | u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') | |
236 | u.login = 'foo' |
|
236 | u.login = 'foo' | |
@@ -238,7 +238,7 class UsersControllerTest < ActionController::TestCase | |||||
238 | u.save! |
|
238 | u.save! | |
239 | ActionMailer::Base.deliveries.clear |
|
239 | ActionMailer::Base.deliveries.clear | |
240 | Setting.bcc_recipients = '1' |
|
240 | Setting.bcc_recipients = '1' | |
241 |
|
241 | |||
242 | put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE} |
|
242 | put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE} | |
243 | assert u.reload.active? |
|
243 | assert u.reload.active? | |
244 | mail = ActionMailer::Base.deliveries.last |
|
244 | mail = ActionMailer::Base.deliveries.last | |
@@ -246,15 +246,15 class UsersControllerTest < ActionController::TestCase | |||||
246 | assert_equal ['foo.bar@somenet.foo'], mail.bcc |
|
246 | assert_equal ['foo.bar@somenet.foo'], mail.bcc | |
247 | assert mail.body.include?(ll('fr', :notice_account_activated)) |
|
247 | assert mail.body.include?(ll('fr', :notice_account_activated)) | |
248 | end |
|
248 | end | |
249 |
|
249 | |||
250 | def test_update_with_password_change_should_send_a_notification |
|
250 | def test_update_with_password_change_should_send_a_notification | |
251 | ActionMailer::Base.deliveries.clear |
|
251 | ActionMailer::Base.deliveries.clear | |
252 | Setting.bcc_recipients = '1' |
|
252 | Setting.bcc_recipients = '1' | |
253 |
|
253 | |||
254 | put :update, :id => 2, :user => {:password => 'newpass', :password_confirmation => 'newpass'}, :send_information => '1' |
|
254 | put :update, :id => 2, :user => {:password => 'newpass', :password_confirmation => 'newpass'}, :send_information => '1' | |
255 | u = User.find(2) |
|
255 | u = User.find(2) | |
256 | assert u.check_password?('newpass') |
|
256 | assert u.check_password?('newpass') | |
257 |
|
257 | |||
258 | mail = ActionMailer::Base.deliveries.last |
|
258 | mail = ActionMailer::Base.deliveries.last | |
259 | assert_not_nil mail |
|
259 | assert_not_nil mail | |
260 | assert_equal [u.mail], mail.bcc |
|
260 | assert_equal [u.mail], mail.bcc | |
@@ -272,7 +272,7 class UsersControllerTest < ActionController::TestCase | |||||
272 | assert_equal nil, u.reload.auth_source |
|
272 | assert_equal nil, u.reload.auth_source | |
273 | assert u.check_password?('newpass') |
|
273 | assert u.check_password?('newpass') | |
274 | end |
|
274 | end | |
275 |
|
275 | |||
276 | def test_destroy |
|
276 | def test_destroy | |
277 | assert_difference 'User.count', -1 do |
|
277 | assert_difference 'User.count', -1 do | |
278 | delete :destroy, :id => 2 |
|
278 | delete :destroy, :id => 2 | |
@@ -290,20 +290,20 class UsersControllerTest < ActionController::TestCase | |||||
290 |
|
290 | |||
291 | def test_destroy_should_be_denied_for_non_admin_users |
|
291 | def test_destroy_should_be_denied_for_non_admin_users | |
292 | @request.session[:user_id] = 3 |
|
292 | @request.session[:user_id] = 3 | |
293 |
|
293 | |||
294 | assert_no_difference 'User.count' do |
|
294 | assert_no_difference 'User.count' do | |
295 | get :destroy, :id => 2 |
|
295 | get :destroy, :id => 2 | |
296 | end |
|
296 | end | |
297 | assert_response 403 |
|
297 | assert_response 403 | |
298 | end |
|
298 | end | |
299 |
|
299 | |||
300 | def test_edit_membership |
|
300 | def test_edit_membership | |
301 | post :edit_membership, :id => 2, :membership_id => 1, |
|
301 | post :edit_membership, :id => 2, :membership_id => 1, | |
302 | :membership => { :role_ids => [2]} |
|
302 | :membership => { :role_ids => [2]} | |
303 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
303 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' | |
304 | assert_equal [2], Member.find(1).role_ids |
|
304 | assert_equal [2], Member.find(1).role_ids | |
305 | end |
|
305 | end | |
306 |
|
306 | |||
307 | def test_destroy_membership |
|
307 | def test_destroy_membership | |
308 | post :destroy_membership, :id => 2, :membership_id => 1 |
|
308 | post :destroy_membership, :id => 2, :membership_id => 1 | |
309 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
309 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
General Comments 0
You need to be logged in to leave comments.
Login now