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
@@ -164,108 +164,107
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
@@ -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
@@ -54,101 +54,101
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'
You need to be logged in to leave comments. Login now