Description:
more test on user_admin
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r752:3a8a3897c926 - - 6 files changed: 71 inserted, 59 deleted

@@ -0,0 +1,50
1 + require "application_system_test_case"
2 +
3 + class UsersTest < ApplicationSystemTestCase
4 + # test "visiting the index" do
5 + # visit users_url
6 + #
7 + # assert_selector "h1", text: "User"
8 + # end
9 +
10 + test "add new user and edit" do
11 + login('admin','admin')
12 + within 'header' do
13 + click_on 'Manage'
14 + click_on 'Users', match: :first
15 + end
16 +
17 + assert_text "Users"
18 + assert_text "New user"
19 +
20 + click_on "New user", match: :first
21 + fill_in 'Login', with: 'test1'
22 + fill_in 'Full name', with: 'test1 McTestface'
23 + fill_in 'e-mail', with: 'a@a.com'
24 + fill_in 'Password', with: 'abcdef'
25 + fill_in 'Password confirmation', with: 'abcdef'
26 +
27 + click_on 'Create'
28 +
29 + assert_text 'User was successfully created'
30 + assert_text 'a@a.com'
31 + assert_text 'test1 McTestface'
32 +
33 + within('tr', text: 'McTestface') do
34 + click_on 'Edit'
35 + end
36 +
37 + fill_in 'Alias', with: 'hahaha'
38 + fill_in 'Remark', with: 'section 2'
39 + click_on 'Update User'
40 +
41 + assert_text 'section 2'
42 + end
43 +
44 + def login(username,password)
45 + visit root_path
46 + fill_in "Login", with: username
47 + fill_in "Password", with: password
48 + click_on "Login"
49 + end
50 + end
@@ -116,204 +116,203
116 116 redirect_to :action => 'index'
117 117 end
118 118
119 119 def edit
120 120 @user = User.find(params[:id])
121 121 end
122 122
123 123 def update
124 124 @user = User.find(params[:id])
125 125 if @user.update_attributes(user_params)
126 126 flash[:notice] = 'User was successfully updated.'
127 127 redirect_to :action => 'show', :id => @user
128 128 else
129 129 render :action => 'edit'
130 130 end
131 131 end
132 132
133 133 def destroy
134 134 User.find(params[:id]).destroy
135 135 redirect_to :action => 'index'
136 136 end
137 137
138 138 def user_stat
139 139 if params[:commit] == 'download csv'
140 140 @problems = Problem.all
141 141 else
142 142 @problems = Problem.available_problems
143 143 end
144 144 @users = User.includes(:contests, :contest_stat).where(enabled: true)
145 145 @scorearray = Array.new
146 146 @users.each do |u|
147 147 ustat = Array.new
148 148 ustat[0] = u
149 149 @problems.each do |p|
150 150 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
151 151 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
152 152 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
153 153 else
154 154 ustat << [0,false]
155 155 end
156 156 end
157 157 @scorearray << ustat
158 158 end
159 159 if params[:commit] == 'download csv' then
160 160 csv = gen_csv_from_scorearray(@scorearray,@problems)
161 161 send_data csv, filename: 'last_score.csv'
162 162 else
163 163 render template: 'user_admin/user_stat'
164 164 end
165 165 end
166 166
167 167 def user_stat_max
168 168 if params[:commit] == 'download csv'
169 169 @problems = Problem.all
170 170 else
171 171 @problems = Problem.available_problems
172 172 end
173 173 @users = User.includes(:contests).includes(:contest_stat).all
174 174 @scorearray = Array.new
175 175 #set up range from param
176 176 since_id = params.fetch(:since_id, 0).to_i
177 177 until_id = params.fetch(:until_id, 0).to_i
178 178 @users.each do |u|
179 179 ustat = Array.new
180 180 ustat[0] = u
181 181 @problems.each do |p|
182 182 max_points = 0
183 183 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
184 184 max_points = sub.points if sub and sub.points and (sub.points > max_points)
185 185 end
186 186 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
187 187 end
188 188 @scorearray << ustat
189 189 end
190 190
191 191 if params[:commit] == 'download csv' then
192 192 csv = gen_csv_from_scorearray(@scorearray,@problems)
193 193 send_data csv, filename: 'max_score.csv'
194 194 else
195 195 render template: 'user_admin/user_stat'
196 196 end
197 197 end
198 198
199 199 def import
200 200 if params[:file]==''
201 201 flash[:notice] = 'Error importing no file'
202 202 redirect_to :action => 'index' and return
203 203 end
204 204 import_from_file(params[:file])
205 205 end
206 206
207 207 def random_all_passwords
208 208 users = User.all
209 209 @prefix = params[:prefix] || ''
210 210 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
211 211 @changed = false
212 - if request.request_method == 'POST'
212 + if params[:commit] == 'Go ahead'
213 213 @non_admin_users.each do |user|
214 214 password = random_password
215 215 user.password = password
216 216 user.password_confirmation = password
217 217 user.save
218 218 end
219 219 @changed = true
220 220 end
221 221 end
222 222
223 -
224 223 # contest management
225 224
226 225 def contests
227 226 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
228 227 @contests = Contest.enabled
229 228 end
230 229
231 230 def assign_from_list
232 231 contest_id = params[:users_contest_id]
233 232 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
234 233 contest = Contest.find(params[:new_contest][:id])
235 234 if !contest
236 235 flash[:notice] = 'Error: no contest'
237 236 redirect_to :action => 'contests', :id =>contest_id
238 237 end
239 238
240 239 note = []
241 240 users.each do |u|
242 241 u.contests = [contest]
243 242 note << u.login
244 243 end
245 244 flash[:notice] = 'User(s) ' + note.join(', ') +
246 245 " were successfully reassigned to #{contest.title}."
247 246 redirect_to :action => 'contests', :id =>contest.id
248 247 end
249 248
250 249 def add_to_contest
251 250 user = User.find(params[:id])
252 251 contest = Contest.find(params[:contest_id])
253 252 if user and contest
254 253 user.contests << contest
255 254 end
256 255 redirect_to :action => 'index'
257 256 end
258 257
259 258 def remove_from_contest
260 259 user = User.find(params[:id])
261 260 contest = Contest.find(params[:contest_id])
262 261 if user and contest
263 262 user.contests.delete(contest)
264 263 end
265 264 redirect_to :action => 'index'
266 265 end
267 266
268 267 def contest_management
269 268 end
270 269
271 270 def manage_contest
272 271 contest = Contest.find(params[:contest][:id])
273 272 if !contest
274 273 flash[:notice] = 'You did not choose the contest.'
275 274 redirect_to :action => 'contest_management' and return
276 275 end
277 276
278 277 operation = params[:operation]
279 278
280 279 if not ['add','remove','assign'].include? operation
281 280 flash[:notice] = 'You did not choose the operation to perform.'
282 281 redirect_to :action => 'contest_management' and return
283 282 end
284 283
285 284 lines = params[:login_list]
286 285 if !lines or lines.blank?
287 286 flash[:notice] = 'You entered an empty list.'
288 287 redirect_to :action => 'contest_management' and return
289 288 end
290 289
291 290 note = []
292 291 users = []
293 292 lines.split("\n").each do |line|
294 293 user = User.find_by_login(line.chomp)
295 294 if user
296 295 if operation=='add'
297 296 if ! user.contests.include? contest
298 297 user.contests << contest
299 298 end
300 299 elsif operation=='remove'
301 300 user.contests.delete(contest)
302 301 else
303 302 user.contests = [contest]
304 303 end
305 304
306 305 if params[:reset_timer]
307 306 user.contest_stat.forced_logout = true
308 307 user.contest_stat.reset_timer_and_save
309 308 end
310 309
311 310 if params[:notification_emails]
312 311 send_contest_update_notification_email(user, contest)
313 312 end
314 313
315 314 note << user.login
316 315 users << user
317 316 end
318 317 end
319 318
@@ -1,38 +1,14
1 - = error_messages_for 'user'
2 - / [form:user]
3 - .form-group
4 - %label.col-md-2.control-label{for: :login} Login
5 - .col-md-4
6 - = text_field 'user', 'login', class: 'form-control'
7 - .col-md-6
8 - .form-group
9 - %label.col-md-2.control-label{for: :full_name} Full name
10 - .col-md-4
11 - = text_field 'user', 'full_name', class: 'form-control'
12 - .col-md-6
13 - .form-group
14 - %label.col-md-2.control-label{for: :password} Password
15 - .col-md-4
16 - = password_field 'user', 'password', class: 'form-control'
17 - .col-md-6
18 - .form-group
19 - %label.col-md-2.control-label{for: :password_confirmation} Password (confirm)
20 - .col-md-4
21 - = password_field 'user', 'password_confirmation', class: 'form-control'
22 - .col-md-6
23 - .form-group
24 - %label.col-md-2.control-label{for: :email} E-mail
25 - .col-md-4
26 - = email_field 'user', 'email', class: 'form-control'
27 - .col-md-6
28 - .form-group
29 - %label.col-md-2.control-label{for: :alias} Alias
30 - .col-md-4
31 - = text_field 'user', 'alias', class: 'form-control'
32 - .col-md-6
33 - .form-group
34 - %label.col-md-2.control-label{for: :remark} Remark
35 - .col-md-4
36 - = text_field 'user', 'remark', class: 'form-control'
37 - .col-md-6
38 - / [eoform:user]
1 + = simple_form_for(@user) do |f|
2 + = f.error_notification
3 + .row
4 + .col-md-6.col-md-offset-2
5 + = f.input :login, label: 'Login'
6 + = f.input :full_name, label: 'Full name'
7 + = f.input :password
8 + = f.input :password_confirmation
9 + = f.input :email
10 + = f.input :alias
11 + = f.input :remark
12 + = f.button :submit, class: 'btn btn-success'
13 + = link_to 'Cancel', :back, class: 'btn btn-default'
14 +
@@ -1,13 +1,4
1 1 %h1 Editing user
2 + = simple_form_for @user, url: user_admin_path(@user) do |f|
3 + = render partial: 'form', local: f
2 4
3 - = form_tag( {:action => 'update', :id => @user}, {class: 'form-horizontal'}) do
4 - = error_messages_for 'user'
5 - = render partial: "form"
6 - .form-group
7 - .col-md-offset-2.col-md-4
8 - = submit_tag "Edit", class: 'btn btn-primary'
9 -
10 -
11 - = link_to 'Show', :action => 'show', :id => @user
12 - |
13 - = link_to 'Back', :action => 'index'
@@ -1,7 +1,3
1 1 %h1 New user
2 - = form_tag( {action: 'create'}, { class: 'form-horizontal'}) do
3 - = render :partial => 'form'
4 - .form-group
5 - .col-md-offset-2.col-md-10
6 - = submit_tag "Create", class: 'btn btn-primary'
7 - = link_to 'Back', :action => 'index'
2 + = simple_form_for @user, url: user_admin_index_path do |f|
3 + = render partial: 'form', local: f
@@ -6,166 +6,166
6 6
7 7 #logins
8 8 match 'login/login', to: 'login#login', via: [:get,:post]
9 9
10 10
11 11 resources :contests
12 12
13 13 resources :sites
14 14
15 15 resources :test
16 16
17 17 resources :messages do
18 18 collection do
19 19 get 'console'
20 20 end
21 21 end
22 22
23 23 resources :announcements do
24 24 member do
25 25 get 'toggle','toggle_front'
26 26 end
27 27 end
28 28
29 29 resources :problems do
30 30 member do
31 31 get 'toggle'
32 32 get 'toggle_test'
33 33 get 'toggle_view_testcase'
34 34 get 'stat'
35 35 end
36 36 collection do
37 37 get 'turn_all_off'
38 38 get 'turn_all_on'
39 39 get 'import'
40 40 get 'manage'
41 41 get 'quick_create'
42 42 post 'do_manage'
43 43 end
44 44 end
45 45
46 46 resources :groups do
47 47 member do
48 48 post 'add_user', to: 'groups#add_user', as: 'add_user'
49 49 delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user'
50 50 delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user'
51 51 post 'add_problem', to: 'groups#add_problem', as: 'add_problem'
52 52 delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem'
53 53 delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem'
54 54 end
55 55 collection do
56 56
57 57 end
58 58 end
59 59
60 60 resources :testcases, only: [] do
61 61 member do
62 62 get 'download_input'
63 63 get 'download_sol'
64 64 end
65 65 collection do
66 66 get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem'
67 67 end
68 68 end
69 69
70 70 resources :grader_configuration, controller: 'configurations'
71 71
72 72 resources :users do
73 73 member do
74 74 get 'toggle_activate', 'toggle_enable'
75 75 get 'stat'
76 76 end
77 77 end
78 78
79 79 resources :submissions do
80 80 member do
81 81 get 'download'
82 82 get 'compiler_msg'
83 83 get 'rejudge'
84 84 end
85 85 collection do
86 86 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
87 87 get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
88 88 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
89 89 end
90 90 end
91 91
92 92
93 93 #user admin
94 94 resources :user_admin do
95 95 collection do
96 96 match 'bulk_manage', via: [:get, :post]
97 97 get 'bulk_mail'
98 98 get 'user_stat'
99 99 get 'import'
100 100 get 'new_list'
101 101 get 'admin'
102 - get 'random_all_passwords'
103 102 get 'active'
104 103 get 'mass_mailing'
104 + post 'grant_admin'
105 105 match 'create_from_list', via: [:get, :post]
106 - post 'grant_admin'
106 + match 'random_all_passwords', via: [:get, :post]
107 107 end
108 108 member do
109 109 get 'clear_last_ip'
110 110 end
111 111 end
112 112
113 113 resources :contest_management, only: [:index] do
114 114 collection do
115 115 get 'user_stat'
116 116 get 'clear_stat'
117 117 get 'clear_all_stat'
118 118 end
119 119 end
120 120
121 121 #get 'user_admin', to: 'user_admin#index'
122 122 #get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
123 123 #post 'user_admin', to: 'user_admin#create'
124 124 #delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy'
125 125
126 126 #singular resource
127 127 #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly
128 128 #report
129 129 resource :report, only: [], controller: 'report' do
130 130 get 'login'
131 131 get 'multiple_login'
132 132 get 'problem_hof/:id', action: 'problem_hof'
133 133 get 'current_score'
134 134 get 'max_score'
135 135 post 'show_max_score'
136 136 end
137 137 #get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
138 138 #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
139 139 #get "report/login"
140 140 #get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
141 141 #post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
142 142
143 143 resource :main, only: [], controller: 'main' do
144 144 get 'list'
145 145 get 'submission(/:id)', action: 'submission', as: 'main_submission'
146 146 post 'submit'
147 147 get 'announcements'
148 148 get 'help'
149 149 end
150 150 #main
151 151 #get "main/list"
152 152 #get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
153 153 #post 'main/submit', to: 'main#submit'
154 154 #get 'main/announcements', to: 'main#announcements'
155 155
156 156
157 157 #
158 158 get 'tasks/view/:file.:ext' => 'tasks#view'
159 159 get 'tasks/download/:id/:file.:ext' => 'tasks#download'
160 160 get 'heartbeat/:id/edit' => 'heartbeat#edit'
161 161
162 162 #grader
163 163 get 'graders/list', to: 'graders#list', as: 'grader_list'
164 164
165 165
166 166 # See how all your routes lay out with "rake routes"
167 167
168 168 # This is a legacy wild controller route that's not recommended for RESTful applications.
169 169 # Note: This route will make all actions in every controller accessible via GET requests.
170 170 # match ':controller(/:action(/:id))(.:format)', via: [:get, :post]
171 171 end
You need to be logged in to leave comments. Login now