@@ -1,13 +1,13 | |||||
1 | <p> |
|
1 | <p> | |
2 | <%= label_tag "user_mail_notification", l(:description_user_mail_notification), :class => "hidden-for-sighted" %> |
|
2 | <%= label_tag "user_mail_notification", l(:description_user_mail_notification), :class => "hidden-for-sighted" %> | |
3 | <%= select_tag 'user[mail_notification]', options_for_select(user_mail_notification_options(@user), @user.mail_notification), |
|
3 | <%= select_tag 'user[mail_notification]', options_for_select(user_mail_notification_options(@user), @user.mail_notification), | |
4 | :onchange => 'if (this.value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %> |
|
4 | :onchange => 'if (this.value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %> | |
5 | </p> |
|
5 | </p> | |
6 | <% content_tag 'div', :id => 'notified-projects', :style => (@user.mail_notification == 'selected' ? '' : 'display:none;') do %> |
|
6 | <%= content_tag 'div', :id => 'notified-projects', :style => (@user.mail_notification == 'selected' ? '' : 'display:none;') do %> | |
7 | <p><% @user.projects.each do |project| %> |
|
7 | <p><% @user.projects.each do |project| %> | |
8 | <label><%= check_box_tag 'notified_project_ids[]', project.id, @user.notified_projects_ids.include?(project.id) %> <%=h project.name %></label><br /> |
|
8 | <label><%= check_box_tag 'notified_project_ids[]', project.id, @user.notified_projects_ids.include?(project.id) %> <%=h project.name %></label><br /> | |
9 | <% end %></p> |
|
9 | <% end %></p> | |
10 | <p><em class="info"><%= l(:text_user_mail_option) %></em></p> |
|
10 | <p><em class="info"><%= l(:text_user_mail_option) %></em></p> | |
11 | <% end %> |
|
11 | <% end %> | |
12 | <p><label><%= l(:label_user_mail_no_self_notified) %><%= check_box_tag 'no_self_notified', 1, @user.pref[:no_self_notified] %></label></p> |
|
12 | <p><label><%= l(:label_user_mail_no_self_notified) %><%= check_box_tag 'no_self_notified', 1, @user.pref[:no_self_notified] %></label></p> | |
13 |
|
13 |
@@ -1,392 +1,415 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 | require 'users_controller' |
|
19 | require 'users_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class UsersController; def rescue_action(e) raise e end; end |
|
22 | 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, |
|
27 | fixtures :users, :projects, :members, :member_roles, :roles, | |
28 | :custom_fields, :custom_values, :groups_users, |
|
28 | :custom_fields, :custom_values, :groups_users, | |
29 | :auth_sources |
|
29 | :auth_sources | |
30 |
|
30 | |||
31 | def setup |
|
31 | def setup | |
32 | @controller = UsersController.new |
|
32 | @controller = UsersController.new | |
33 | @request = ActionController::TestRequest.new |
|
33 | @request = ActionController::TestRequest.new | |
34 | @response = ActionController::TestResponse.new |
|
34 | @response = ActionController::TestResponse.new | |
35 | User.current = nil |
|
35 | User.current = nil | |
36 | @request.session[:user_id] = 1 # admin |
|
36 | @request.session[:user_id] = 1 # admin | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def test_index |
|
39 | def test_index | |
40 | get :index |
|
40 | get :index | |
41 | assert_response :success |
|
41 | assert_response :success | |
42 | assert_template 'index' |
|
42 | assert_template 'index' | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | def test_index |
|
45 | def test_index | |
46 | get :index |
|
46 | get :index | |
47 | assert_response :success |
|
47 | assert_response :success | |
48 | assert_template 'index' |
|
48 | assert_template 'index' | |
49 | assert_not_nil assigns(:users) |
|
49 | assert_not_nil assigns(:users) | |
50 | # active users only |
|
50 | # active users only | |
51 | assert_nil assigns(:users).detect {|u| !u.active?} |
|
51 | assert_nil assigns(:users).detect {|u| !u.active?} | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def test_index_with_status_filter |
|
54 | def test_index_with_status_filter | |
55 | get :index, :status => 3 |
|
55 | get :index, :status => 3 | |
56 | assert_response :success |
|
56 | assert_response :success | |
57 | assert_template 'index' |
|
57 | assert_template 'index' | |
58 | assert_not_nil assigns(:users) |
|
58 | assert_not_nil assigns(:users) | |
59 | assert_equal [3], assigns(:users).map(&:status).uniq |
|
59 | assert_equal [3], assigns(:users).map(&:status).uniq | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | def test_index_with_name_filter |
|
62 | def test_index_with_name_filter | |
63 | get :index, :name => 'john' |
|
63 | get :index, :name => 'john' | |
64 | assert_response :success |
|
64 | assert_response :success | |
65 | assert_template 'index' |
|
65 | assert_template 'index' | |
66 | users = assigns(:users) |
|
66 | users = assigns(:users) | |
67 | assert_not_nil users |
|
67 | assert_not_nil users | |
68 | assert_equal 1, users.size |
|
68 | assert_equal 1, users.size | |
69 | assert_equal 'John', users.first.firstname |
|
69 | assert_equal 'John', users.first.firstname | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def test_index_with_group_filter |
|
72 | def test_index_with_group_filter | |
73 | get :index, :group_id => '10' |
|
73 | get :index, :group_id => '10' | |
74 | assert_response :success |
|
74 | assert_response :success | |
75 | assert_template 'index' |
|
75 | assert_template 'index' | |
76 | users = assigns(:users) |
|
76 | users = assigns(:users) | |
77 | assert users.any? |
|
77 | assert users.any? | |
78 | assert_equal([], (users - Group.find(10).users)) |
|
78 | assert_equal([], (users - Group.find(10).users)) | |
79 | assert_select 'select[name=group_id]' do |
|
79 | assert_select 'select[name=group_id]' do | |
80 | assert_select 'option[value=10][selected=selected]' |
|
80 | assert_select 'option[value=10][selected=selected]' | |
81 | end |
|
81 | end | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_show |
|
84 | def test_show | |
85 | @request.session[:user_id] = nil |
|
85 | @request.session[:user_id] = nil | |
86 | get :show, :id => 2 |
|
86 | get :show, :id => 2 | |
87 | assert_response :success |
|
87 | assert_response :success | |
88 | assert_template 'show' |
|
88 | assert_template 'show' | |
89 | assert_not_nil assigns(:user) |
|
89 | assert_not_nil assigns(:user) | |
90 |
|
90 | |||
91 | assert_tag 'li', :content => /Phone number/ |
|
91 | assert_tag 'li', :content => /Phone number/ | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | def test_show_should_not_display_hidden_custom_fields |
|
94 | def test_show_should_not_display_hidden_custom_fields | |
95 | @request.session[:user_id] = nil |
|
95 | @request.session[:user_id] = nil | |
96 | UserCustomField.find_by_name('Phone number').update_attribute :visible, false |
|
96 | UserCustomField.find_by_name('Phone number').update_attribute :visible, false | |
97 | get :show, :id => 2 |
|
97 | get :show, :id => 2 | |
98 | assert_response :success |
|
98 | assert_response :success | |
99 | assert_template 'show' |
|
99 | assert_template 'show' | |
100 | assert_not_nil assigns(:user) |
|
100 | assert_not_nil assigns(:user) | |
101 |
|
101 | |||
102 | assert_no_tag 'li', :content => /Phone number/ |
|
102 | assert_no_tag 'li', :content => /Phone number/ | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | def test_show_should_not_fail_when_custom_values_are_nil |
|
105 | def test_show_should_not_fail_when_custom_values_are_nil | |
106 | user = User.find(2) |
|
106 | user = User.find(2) | |
107 |
|
107 | |||
108 | # Create a custom field to illustrate the issue |
|
108 | # Create a custom field to illustrate the issue | |
109 | custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text') |
|
109 | custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text') | |
110 | custom_value = user.custom_values.build(:custom_field => custom_field).save! |
|
110 | custom_value = user.custom_values.build(:custom_field => custom_field).save! | |
111 |
|
111 | |||
112 | get :show, :id => 2 |
|
112 | get :show, :id => 2 | |
113 | assert_response :success |
|
113 | assert_response :success | |
114 | end |
|
114 | end | |
115 |
|
115 | |||
116 | def test_show_inactive |
|
116 | def test_show_inactive | |
117 | @request.session[:user_id] = nil |
|
117 | @request.session[:user_id] = nil | |
118 | get :show, :id => 5 |
|
118 | get :show, :id => 5 | |
119 | assert_response 404 |
|
119 | assert_response 404 | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | def test_show_should_not_reveal_users_with_no_visible_activity_or_project |
|
122 | def test_show_should_not_reveal_users_with_no_visible_activity_or_project | |
123 | @request.session[:user_id] = nil |
|
123 | @request.session[:user_id] = nil | |
124 | get :show, :id => 9 |
|
124 | get :show, :id => 9 | |
125 | assert_response 404 |
|
125 | assert_response 404 | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def test_show_inactive_by_admin |
|
128 | def test_show_inactive_by_admin | |
129 | @request.session[:user_id] = 1 |
|
129 | @request.session[:user_id] = 1 | |
130 | get :show, :id => 5 |
|
130 | get :show, :id => 5 | |
131 | assert_response 200 |
|
131 | assert_response 200 | |
132 | assert_not_nil assigns(:user) |
|
132 | assert_not_nil assigns(:user) | |
133 | end |
|
133 | end | |
134 |
|
134 | |||
135 | def test_show_displays_memberships_based_on_project_visibility |
|
135 | def test_show_displays_memberships_based_on_project_visibility | |
136 | @request.session[:user_id] = 1 |
|
136 | @request.session[:user_id] = 1 | |
137 | get :show, :id => 2 |
|
137 | get :show, :id => 2 | |
138 | assert_response :success |
|
138 | assert_response :success | |
139 | memberships = assigns(:memberships) |
|
139 | memberships = assigns(:memberships) | |
140 | assert_not_nil memberships |
|
140 | assert_not_nil memberships | |
141 | project_ids = memberships.map(&:project_id) |
|
141 | project_ids = memberships.map(&:project_id) | |
142 | assert project_ids.include?(2) #private project admin can see |
|
142 | assert project_ids.include?(2) #private project admin can see | |
143 | end |
|
143 | end | |
144 |
|
144 | |||
145 | def test_show_current_should_require_authentication |
|
145 | def test_show_current_should_require_authentication | |
146 | @request.session[:user_id] = nil |
|
146 | @request.session[:user_id] = nil | |
147 | get :show, :id => 'current' |
|
147 | get :show, :id => 'current' | |
148 | assert_response 302 |
|
148 | assert_response 302 | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | def test_show_current |
|
151 | def test_show_current | |
152 | @request.session[:user_id] = 2 |
|
152 | @request.session[:user_id] = 2 | |
153 | get :show, :id => 'current' |
|
153 | get :show, :id => 'current' | |
154 | assert_response :success |
|
154 | assert_response :success | |
155 | assert_template 'show' |
|
155 | assert_template 'show' | |
156 | assert_equal User.find(2), assigns(:user) |
|
156 | assert_equal User.find(2), assigns(:user) | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | def test_new |
|
159 | def test_new | |
160 | get :new |
|
160 | get :new | |
161 | assert_response :success |
|
161 | assert_response :success | |
162 | assert_template :new |
|
162 | assert_template :new | |
163 | assert assigns(:user) |
|
163 | assert assigns(:user) | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | def test_create |
|
166 | def test_create | |
167 | Setting.bcc_recipients = '1' |
|
167 | Setting.bcc_recipients = '1' | |
168 |
|
168 | |||
169 | assert_difference 'User.count' do |
|
169 | assert_difference 'User.count' do | |
170 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
170 | assert_difference 'ActionMailer::Base.deliveries.size' do | |
171 | post :create, |
|
171 | post :create, | |
172 | :user => { |
|
172 | :user => { | |
173 | :firstname => 'John', |
|
173 | :firstname => 'John', | |
174 | :lastname => 'Doe', |
|
174 | :lastname => 'Doe', | |
175 | :login => 'jdoe', |
|
175 | :login => 'jdoe', | |
176 | :password => 'secret', |
|
176 | :password => 'secret', | |
177 | :password_confirmation => 'secret', |
|
177 | :password_confirmation => 'secret', | |
178 | :mail => 'jdoe@gmail.com', |
|
178 | :mail => 'jdoe@gmail.com', | |
179 | :mail_notification => 'none' |
|
179 | :mail_notification => 'none' | |
180 | }, |
|
180 | }, | |
181 | :send_information => '1' |
|
181 | :send_information => '1' | |
182 | end |
|
182 | end | |
183 | end |
|
183 | end | |
184 |
|
184 | |||
185 | user = User.first(:order => 'id DESC') |
|
185 | user = User.first(:order => 'id DESC') | |
186 | assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id |
|
186 | assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id | |
187 |
|
187 | |||
188 | assert_equal 'John', user.firstname |
|
188 | assert_equal 'John', user.firstname | |
189 | assert_equal 'Doe', user.lastname |
|
189 | assert_equal 'Doe', user.lastname | |
190 | assert_equal 'jdoe', user.login |
|
190 | assert_equal 'jdoe', user.login | |
191 | assert_equal 'jdoe@gmail.com', user.mail |
|
191 | assert_equal 'jdoe@gmail.com', user.mail | |
192 | assert_equal 'none', user.mail_notification |
|
192 | assert_equal 'none', user.mail_notification | |
193 | assert user.check_password?('secret') |
|
193 | assert user.check_password?('secret') | |
194 |
|
194 | |||
195 | mail = ActionMailer::Base.deliveries.last |
|
195 | mail = ActionMailer::Base.deliveries.last | |
196 | assert_not_nil mail |
|
196 | assert_not_nil mail | |
197 | assert_equal [user.mail], mail.bcc |
|
197 | assert_equal [user.mail], mail.bcc | |
198 | assert_mail_body_match 'secret', mail |
|
198 | assert_mail_body_match 'secret', mail | |
199 | end |
|
199 | end | |
200 |
|
200 | |||
201 | def test_create_with_preferences |
|
201 | def test_create_with_preferences | |
202 | assert_difference 'User.count' do |
|
202 | assert_difference 'User.count' do | |
203 | post :create, |
|
203 | post :create, | |
204 | :user => { |
|
204 | :user => { | |
205 | :firstname => 'John', |
|
205 | :firstname => 'John', | |
206 | :lastname => 'Doe', |
|
206 | :lastname => 'Doe', | |
207 | :login => 'jdoe', |
|
207 | :login => 'jdoe', | |
208 | :password => 'secret', |
|
208 | :password => 'secret', | |
209 | :password_confirmation => 'secret', |
|
209 | :password_confirmation => 'secret', | |
210 | :mail => 'jdoe@gmail.com', |
|
210 | :mail => 'jdoe@gmail.com', | |
211 | :mail_notification => 'none' |
|
211 | :mail_notification => 'none' | |
212 | }, |
|
212 | }, | |
213 | :pref => { |
|
213 | :pref => { | |
214 | 'hide_mail' => '1', |
|
214 | 'hide_mail' => '1', | |
215 | 'time_zone' => 'Paris', |
|
215 | 'time_zone' => 'Paris', | |
216 | 'comments_sorting' => 'desc', |
|
216 | 'comments_sorting' => 'desc', | |
217 | 'warn_on_leaving_unsaved' => '0' |
|
217 | 'warn_on_leaving_unsaved' => '0' | |
218 | } |
|
218 | } | |
219 | end |
|
219 | end | |
220 | user = User.first(:order => 'id DESC') |
|
220 | user = User.first(:order => 'id DESC') | |
221 | assert_equal 'jdoe', user.login |
|
221 | assert_equal 'jdoe', user.login | |
222 | assert_equal true, user.pref.hide_mail |
|
222 | assert_equal true, user.pref.hide_mail | |
223 | assert_equal 'Paris', user.pref.time_zone |
|
223 | assert_equal 'Paris', user.pref.time_zone | |
224 | assert_equal 'desc', user.pref[:comments_sorting] |
|
224 | assert_equal 'desc', user.pref[:comments_sorting] | |
225 | assert_equal '0', user.pref[:warn_on_leaving_unsaved] |
|
225 | assert_equal '0', user.pref[:warn_on_leaving_unsaved] | |
226 | end |
|
226 | end | |
227 |
|
227 | |||
228 | def test_create_with_failure |
|
228 | def test_create_with_failure | |
229 | assert_no_difference 'User.count' do |
|
229 | assert_no_difference 'User.count' do | |
230 | post :create, :user => {} |
|
230 | post :create, :user => {} | |
231 | end |
|
231 | end | |
232 | assert_response :success |
|
232 | assert_response :success | |
233 | assert_template 'new' |
|
233 | assert_template 'new' | |
234 | end |
|
234 | end | |
235 |
|
235 | |||
236 | def test_edit |
|
236 | def test_edit | |
237 | get :edit, :id => 2 |
|
237 | get :edit, :id => 2 | |
238 | assert_response :success |
|
238 | assert_response :success | |
239 | assert_template 'edit' |
|
239 | assert_template 'edit' | |
240 | assert_equal User.find(2), assigns(:user) |
|
240 | assert_equal User.find(2), assigns(:user) | |
241 | end |
|
241 | end | |
242 |
|
242 | |||
243 | def test_update |
|
243 | def test_update | |
244 | ActionMailer::Base.deliveries.clear |
|
244 | ActionMailer::Base.deliveries.clear | |
245 | put :update, :id => 2, |
|
245 | put :update, :id => 2, | |
246 | :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, |
|
246 | :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, | |
247 | :pref => {:hide_mail => '1', :comments_sorting => 'desc'} |
|
247 | :pref => {:hide_mail => '1', :comments_sorting => 'desc'} | |
248 | user = User.find(2) |
|
248 | user = User.find(2) | |
249 | assert_equal 'Changed', user.firstname |
|
249 | assert_equal 'Changed', user.firstname | |
250 | assert_equal 'only_assigned', user.mail_notification |
|
250 | assert_equal 'only_assigned', user.mail_notification | |
251 | assert_equal true, user.pref[:hide_mail] |
|
251 | assert_equal true, user.pref[:hide_mail] | |
252 | assert_equal 'desc', user.pref[:comments_sorting] |
|
252 | assert_equal 'desc', user.pref[:comments_sorting] | |
253 | assert ActionMailer::Base.deliveries.empty? |
|
253 | assert ActionMailer::Base.deliveries.empty? | |
254 | end |
|
254 | end | |
255 |
|
255 | |||
256 | def test_update_with_failure |
|
256 | def test_update_with_failure | |
257 | assert_no_difference 'User.count' do |
|
257 | assert_no_difference 'User.count' do | |
258 | put :update, :id => 2, :user => {:firstname => ''} |
|
258 | put :update, :id => 2, :user => {:firstname => ''} | |
259 | end |
|
259 | end | |
260 | assert_response :success |
|
260 | assert_response :success | |
261 | assert_template 'edit' |
|
261 | assert_template 'edit' | |
262 | end |
|
262 | end | |
263 |
|
263 | |||
264 | def test_update_with_group_ids_should_assign_groups |
|
264 | def test_update_with_group_ids_should_assign_groups | |
265 | put :update, :id => 2, :user => {:group_ids => ['10']} |
|
265 | put :update, :id => 2, :user => {:group_ids => ['10']} | |
266 | user = User.find(2) |
|
266 | user = User.find(2) | |
267 | assert_equal [10], user.group_ids |
|
267 | assert_equal [10], user.group_ids | |
268 | end |
|
268 | end | |
269 |
|
269 | |||
270 | def test_update_with_activation_should_send_a_notification |
|
270 | def test_update_with_activation_should_send_a_notification | |
271 | u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') |
|
271 | u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') | |
272 | u.login = 'foo' |
|
272 | u.login = 'foo' | |
273 | u.status = User::STATUS_REGISTERED |
|
273 | u.status = User::STATUS_REGISTERED | |
274 | u.save! |
|
274 | u.save! | |
275 | ActionMailer::Base.deliveries.clear |
|
275 | ActionMailer::Base.deliveries.clear | |
276 | Setting.bcc_recipients = '1' |
|
276 | Setting.bcc_recipients = '1' | |
277 |
|
277 | |||
278 | put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE} |
|
278 | put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE} | |
279 | assert u.reload.active? |
|
279 | assert u.reload.active? | |
280 | mail = ActionMailer::Base.deliveries.last |
|
280 | mail = ActionMailer::Base.deliveries.last | |
281 | assert_not_nil mail |
|
281 | assert_not_nil mail | |
282 | assert_equal ['foo.bar@somenet.foo'], mail.bcc |
|
282 | assert_equal ['foo.bar@somenet.foo'], mail.bcc | |
283 | assert_mail_body_match ll('fr', :notice_account_activated), mail |
|
283 | assert_mail_body_match ll('fr', :notice_account_activated), mail | |
284 | end |
|
284 | end | |
285 |
|
285 | |||
286 | def test_update_with_password_change_should_send_a_notification |
|
286 | def test_update_with_password_change_should_send_a_notification | |
287 | ActionMailer::Base.deliveries.clear |
|
287 | ActionMailer::Base.deliveries.clear | |
288 | Setting.bcc_recipients = '1' |
|
288 | Setting.bcc_recipients = '1' | |
289 |
|
289 | |||
290 | put :update, :id => 2, :user => {:password => 'newpass', :password_confirmation => 'newpass'}, :send_information => '1' |
|
290 | put :update, :id => 2, :user => {:password => 'newpass', :password_confirmation => 'newpass'}, :send_information => '1' | |
291 | u = User.find(2) |
|
291 | u = User.find(2) | |
292 | assert u.check_password?('newpass') |
|
292 | assert u.check_password?('newpass') | |
293 |
|
293 | |||
294 | mail = ActionMailer::Base.deliveries.last |
|
294 | mail = ActionMailer::Base.deliveries.last | |
295 | assert_not_nil mail |
|
295 | assert_not_nil mail | |
296 | assert_equal [u.mail], mail.bcc |
|
296 | assert_equal [u.mail], mail.bcc | |
297 | assert_mail_body_match 'newpass', mail |
|
297 | assert_mail_body_match 'newpass', mail | |
298 | end |
|
298 | end | |
299 |
|
299 | |||
300 | def test_update_user_switchin_from_auth_source_to_password_authentication |
|
300 | def test_update_user_switchin_from_auth_source_to_password_authentication | |
301 | # Configure as auth source |
|
301 | # Configure as auth source | |
302 | u = User.find(2) |
|
302 | u = User.find(2) | |
303 | u.auth_source = AuthSource.find(1) |
|
303 | u.auth_source = AuthSource.find(1) | |
304 | u.save! |
|
304 | u.save! | |
305 |
|
305 | |||
306 | put :update, :id => u.id, :user => {:auth_source_id => '', :password => 'newpass', :password_confirmation => 'newpass'} |
|
306 | put :update, :id => u.id, :user => {:auth_source_id => '', :password => 'newpass', :password_confirmation => 'newpass'} | |
307 |
|
307 | |||
308 | assert_equal nil, u.reload.auth_source |
|
308 | assert_equal nil, u.reload.auth_source | |
309 | assert u.check_password?('newpass') |
|
309 | assert u.check_password?('newpass') | |
310 | end |
|
310 | end | |
311 |
|
311 | |||
|
312 | def test_update_notified_project | |||
|
313 | get :edit, :id => 2 | |||
|
314 | assert_response :success | |||
|
315 | assert_template 'edit' | |||
|
316 | u = User.find(2) | |||
|
317 | assert_equal [1, 2, 5], u.projects.collect{|p| p.id}.sort | |||
|
318 | assert_equal [1, 2, 5], u.notified_projects_ids.sort | |||
|
319 | assert_tag :tag => 'input', | |||
|
320 | :attributes => { | |||
|
321 | :id => 'notified_project_ids_', | |||
|
322 | :value => 1, | |||
|
323 | } | |||
|
324 | assert_equal 'all', u.mail_notification | |||
|
325 | put :update, :id => 2, | |||
|
326 | :user => { | |||
|
327 | :mail_notification => 'selected', | |||
|
328 | }, | |||
|
329 | :notified_project_ids => [1, 2] | |||
|
330 | u = User.find(2) | |||
|
331 | assert_equal 'selected', u.mail_notification | |||
|
332 | assert_equal [1, 2], u.notified_projects_ids.sort | |||
|
333 | end | |||
|
334 | ||||
312 | def test_destroy |
|
335 | def test_destroy | |
313 | assert_difference 'User.count', -1 do |
|
336 | assert_difference 'User.count', -1 do | |
314 | delete :destroy, :id => 2 |
|
337 | delete :destroy, :id => 2 | |
315 | end |
|
338 | end | |
316 | assert_redirected_to '/users' |
|
339 | assert_redirected_to '/users' | |
317 | assert_nil User.find_by_id(2) |
|
340 | assert_nil User.find_by_id(2) | |
318 | end |
|
341 | end | |
319 |
|
342 | |||
320 | def test_destroy_should_be_denied_for_non_admin_users |
|
343 | def test_destroy_should_be_denied_for_non_admin_users | |
321 | @request.session[:user_id] = 3 |
|
344 | @request.session[:user_id] = 3 | |
322 |
|
345 | |||
323 | assert_no_difference 'User.count' do |
|
346 | assert_no_difference 'User.count' do | |
324 | get :destroy, :id => 2 |
|
347 | get :destroy, :id => 2 | |
325 | end |
|
348 | end | |
326 | assert_response 403 |
|
349 | assert_response 403 | |
327 | end |
|
350 | end | |
328 |
|
351 | |||
329 | def test_create_membership |
|
352 | def test_create_membership | |
330 | assert_difference 'Member.count' do |
|
353 | assert_difference 'Member.count' do | |
331 | post :edit_membership, :id => 7, :membership => { :project_id => 3, :role_ids => [2]} |
|
354 | post :edit_membership, :id => 7, :membership => { :project_id => 3, :role_ids => [2]} | |
332 | end |
|
355 | end | |
333 | assert_redirected_to :action => 'edit', :id => '7', :tab => 'memberships' |
|
356 | assert_redirected_to :action => 'edit', :id => '7', :tab => 'memberships' | |
334 | member = Member.first(:order => 'id DESC') |
|
357 | member = Member.first(:order => 'id DESC') | |
335 | assert_equal User.find(7), member.principal |
|
358 | assert_equal User.find(7), member.principal | |
336 | assert_equal [2], member.role_ids |
|
359 | assert_equal [2], member.role_ids | |
337 | assert_equal 3, member.project_id |
|
360 | assert_equal 3, member.project_id | |
338 | end |
|
361 | end | |
339 |
|
362 | |||
340 | def test_create_membership_js_format |
|
363 | def test_create_membership_js_format | |
341 | assert_difference 'Member.count' do |
|
364 | assert_difference 'Member.count' do | |
342 | post :edit_membership, :id => 7, :membership => {:project_id => 3, :role_ids => [2]}, :format => 'js' |
|
365 | post :edit_membership, :id => 7, :membership => {:project_id => 3, :role_ids => [2]}, :format => 'js' | |
343 | end |
|
366 | end | |
344 | assert_response :success |
|
367 | assert_response :success | |
345 | assert_select_rjs :replace_html, 'tab-content-memberships' |
|
368 | assert_select_rjs :replace_html, 'tab-content-memberships' | |
346 | member = Member.first(:order => 'id DESC') |
|
369 | member = Member.first(:order => 'id DESC') | |
347 | assert_equal User.find(7), member.principal |
|
370 | assert_equal User.find(7), member.principal | |
348 | assert_equal [2], member.role_ids |
|
371 | assert_equal [2], member.role_ids | |
349 | assert_equal 3, member.project_id |
|
372 | assert_equal 3, member.project_id | |
350 | end |
|
373 | end | |
351 |
|
374 | |||
352 | def test_create_membership_js_format_with_failure |
|
375 | def test_create_membership_js_format_with_failure | |
353 | assert_no_difference 'Member.count' do |
|
376 | assert_no_difference 'Member.count' do | |
354 | post :edit_membership, :id => 7, :membership => {:project_id => 3}, :format => 'js' |
|
377 | post :edit_membership, :id => 7, :membership => {:project_id => 3}, :format => 'js' | |
355 | end |
|
378 | end | |
356 | assert_response :success |
|
379 | assert_response :success | |
357 | assert @response.body.match(/alert/i), "Alert message not sent" |
|
380 | assert @response.body.match(/alert/i), "Alert message not sent" | |
358 | assert @response.body.match(/role can't be empty/i), "Error message not sent" |
|
381 | assert @response.body.match(/role can't be empty/i), "Error message not sent" | |
359 | end |
|
382 | end | |
360 |
|
383 | |||
361 | def test_update_membership |
|
384 | def test_update_membership | |
362 | assert_no_difference 'Member.count' do |
|
385 | assert_no_difference 'Member.count' do | |
363 | put :edit_membership, :id => 2, :membership_id => 1, :membership => { :role_ids => [2]} |
|
386 | put :edit_membership, :id => 2, :membership_id => 1, :membership => { :role_ids => [2]} | |
364 | end |
|
387 | end | |
365 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
388 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' | |
366 | assert_equal [2], Member.find(1).role_ids |
|
389 | assert_equal [2], Member.find(1).role_ids | |
367 | end |
|
390 | end | |
368 |
|
391 | |||
369 | def test_update_membership_js_format |
|
392 | def test_update_membership_js_format | |
370 | assert_no_difference 'Member.count' do |
|
393 | assert_no_difference 'Member.count' do | |
371 | put :edit_membership, :id => 2, :membership_id => 1, :membership => {:role_ids => [2]}, :format => 'js' |
|
394 | put :edit_membership, :id => 2, :membership_id => 1, :membership => {:role_ids => [2]}, :format => 'js' | |
372 | end |
|
395 | end | |
373 | assert_response :success |
|
396 | assert_response :success | |
374 | assert_select_rjs :replace_html, 'tab-content-memberships' |
|
397 | assert_select_rjs :replace_html, 'tab-content-memberships' | |
375 | end |
|
398 | end | |
376 |
|
399 | |||
377 | def test_destroy_membership |
|
400 | def test_destroy_membership | |
378 | assert_difference 'Member.count', -1 do |
|
401 | assert_difference 'Member.count', -1 do | |
379 | delete :destroy_membership, :id => 2, :membership_id => 1 |
|
402 | delete :destroy_membership, :id => 2, :membership_id => 1 | |
380 | end |
|
403 | end | |
381 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
404 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' | |
382 | assert_nil Member.find_by_id(1) |
|
405 | assert_nil Member.find_by_id(1) | |
383 | end |
|
406 | end | |
384 |
|
407 | |||
385 | def test_destroy_membership_js_format |
|
408 | def test_destroy_membership_js_format | |
386 | assert_difference 'Member.count', -1 do |
|
409 | assert_difference 'Member.count', -1 do | |
387 | delete :destroy_membership, :id => 2, :membership_id => 1, :format => 'js' |
|
410 | delete :destroy_membership, :id => 2, :membership_id => 1, :format => 'js' | |
388 | end |
|
411 | end | |
389 | assert_response :success |
|
412 | assert_response :success | |
390 | assert_select_rjs :replace_html, 'tab-content-memberships' |
|
413 | assert_select_rjs :replace_html, 'tab-content-memberships' | |
391 | end |
|
414 | end | |
392 | end |
|
415 | end |
General Comments 0
You need to be logged in to leave comments.
Login now