Description:
- fix login box - add announcement functional test
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r638:b8cc2bced458 - - 6 files changed: 170 inserted, 121 deleted

@@ -0,0 +1,50
1 + require 'test_helper'
2 +
3 + class AnnouncementsControllerTest < ActionController::TestCase
4 + setup do
5 + @announcement = announcements(:one)
6 + @request.session[:user_id] = users(:admin).id
7 + end
8 +
9 + test "should get index" do
10 + get :index
11 + assert_response :success
12 + assert_not_nil assigns(:announcements)
13 + end
14 +
15 + test "should get new" do
16 + get :new
17 + assert_response :success
18 + end
19 +
20 + test "should create announcement" do
21 + assert_difference('Announcement.count') do
22 + post :create, announcement: { author: 'test', body: 'haha', published: true}
23 + end
24 +
25 + assert_redirected_to announcement_path(assigns(:announcement))
26 + end
27 +
28 + test "should show announcement" do
29 + get :show, id: @announcement
30 + assert_response :success
31 + end
32 +
33 + test "should get edit" do
34 + get :edit, id: @announcement
35 + assert_response :success
36 + end
37 +
38 + test "should update announcement" do
39 + patch :update, id: @announcement, announcement: { body: 'another body' }
40 + assert_redirected_to announcement_path(assigns(:announcement))
41 + end
42 +
43 + test "should destroy announcement" do
44 + assert_difference('Announcement.count', -1) do
45 + delete :destroy, id: @announcement
46 + end
47 +
48 + assert_redirected_to announcements_path
49 + end
50 + end
@@ -0,0 +1,7
1 + require 'test_helper'
2 +
3 + class AdminTaskTest < ActionDispatch::IntegrationTest
4 + # test "the truth" do
5 + # assert true
6 + # end
7 + end
@@ -108,21 +108,19
108 end
108 end
109 return true
109 return true
110 end
110 end
111
111
112 def authorization
112 def authorization
113 return false unless authenticate
113 return false unless authenticate
114 - puts "haha 1"
115 user = User.find(session[:user_id])
114 user = User.find(session[:user_id])
116 unless user.roles.detect { |role|
115 unless user.roles.detect { |role|
117 role.rights.detect{ |right|
116 role.rights.detect{ |right|
118 right.controller == self.class.controller_name and
117 right.controller == self.class.controller_name and
119 (right.action == 'all' or right.action == action_name)
118 (right.action == 'all' or right.action == action_name)
120 }
119 }
121 }
120 }
122 - puts "haha 2"
123 flash[:notice] = 'You are not authorized to view the page you requested'
121 flash[:notice] = 'You are not authorized to view the page you requested'
124 #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login')
122 #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login')
125 redirect_to :controller => 'main', :action => 'login'
123 redirect_to :controller => 'main', :action => 'login'
126 return false
124 return false
127 end
125 end
128 end
126 end
@@ -3,17 +3,15
3
3
4 - if !@hidelogin
4 - if !@hidelogin
5 =t 'login.message'
5 =t 'login.message'
6 %br/
6 %br/
7 %br/
7 %br/
8
8
9 - - puts flash.inspect
10 - if flash[:notice]
9 - if flash[:notice]
11 %hr/
10 %hr/
12 %b= flash[:notice]
11 %b= flash[:notice]
13 - %b= haha
14 %hr/
12 %hr/
15
13
16 %div{ :style => "border: solid 1px gray; padding: 4px; background: #eeeeff;"}
14 %div{ :style => "border: solid 1px gray; padding: 4px; background: #eeeeff;"}
17 = form_tag login_login_path do
15 = form_tag login_login_path do
18 %table
16 %table
19 %tr
17 %tr
@@ -11,271 +11,260
11 #
11 #
12 # It's strongly recommended that you check this file into your version control system.
12 # It's strongly recommended that you check this file into your version control system.
13
13
14 ActiveRecord::Schema.define(version: 20170124024527) do
14 ActiveRecord::Schema.define(version: 20170124024527) do
15
15
16 create_table "announcements", force: :cascade do |t|
16 create_table "announcements", force: :cascade do |t|
17 - t.string "author", limit: 255
17 + t.string "author"
18 - t.text "body", limit: 65535
18 + t.text "body"
19 t.boolean "published"
19 t.boolean "published"
20 t.datetime "created_at", null: false
20 t.datetime "created_at", null: false
21 t.datetime "updated_at", null: false
21 t.datetime "updated_at", null: false
22 t.boolean "frontpage", default: false
22 t.boolean "frontpage", default: false
23 t.boolean "contest_only", default: false
23 t.boolean "contest_only", default: false
24 - t.string "title", limit: 255
24 + t.string "title"
25 - t.string "notes", limit: 255
25 + t.string "notes"
26 end
26 end
27
27
28 create_table "contests", force: :cascade do |t|
28 create_table "contests", force: :cascade do |t|
29 - t.string "title", limit: 255
29 + t.string "title"
30 t.boolean "enabled"
30 t.boolean "enabled"
31 t.datetime "created_at", null: false
31 t.datetime "created_at", null: false
32 t.datetime "updated_at", null: false
32 t.datetime "updated_at", null: false
33 - t.string "name", limit: 255
33 + t.string "name"
34 end
34 end
35
35
36 create_table "contests_problems", id: false, force: :cascade do |t|
36 create_table "contests_problems", id: false, force: :cascade do |t|
37 - t.integer "contest_id", limit: 4
37 + t.integer "contest_id"
38 - t.integer "problem_id", limit: 4
38 + t.integer "problem_id"
39 end
39 end
40
40
41 create_table "contests_users", id: false, force: :cascade do |t|
41 create_table "contests_users", id: false, force: :cascade do |t|
42 - t.integer "contest_id", limit: 4
42 + t.integer "contest_id"
43 - t.integer "user_id", limit: 4
43 + t.integer "user_id"
44 end
44 end
45
45
46 create_table "countries", force: :cascade do |t|
46 create_table "countries", force: :cascade do |t|
47 - t.string "name", limit: 255
47 + t.string "name"
48 t.datetime "created_at", null: false
48 t.datetime "created_at", null: false
49 t.datetime "updated_at", null: false
49 t.datetime "updated_at", null: false
50 end
50 end
51
51
52 create_table "descriptions", force: :cascade do |t|
52 create_table "descriptions", force: :cascade do |t|
53 - t.text "body", limit: 65535
53 + t.text "body"
54 t.boolean "markdowned"
54 t.boolean "markdowned"
55 t.datetime "created_at", null: false
55 t.datetime "created_at", null: false
56 t.datetime "updated_at", null: false
56 t.datetime "updated_at", null: false
57 end
57 end
58
58
59 create_table "grader_configurations", force: :cascade do |t|
59 create_table "grader_configurations", force: :cascade do |t|
60 - t.string "key", limit: 255
60 + t.string "key"
61 - t.string "value_type", limit: 255
61 + t.string "value_type"
62 - t.string "value", limit: 255
62 + t.string "value"
63 t.datetime "created_at", null: false
63 t.datetime "created_at", null: false
64 t.datetime "updated_at", null: false
64 t.datetime "updated_at", null: false
65 - t.text "description", limit: 65535
65 + t.text "description"
66 end
66 end
67
67
68 create_table "grader_processes", force: :cascade do |t|
68 create_table "grader_processes", force: :cascade do |t|
69 - t.string "host", limit: 255
69 + t.string "host"
70 - t.integer "pid", limit: 4
70 + t.integer "pid"
71 - t.string "mode", limit: 255
71 + t.string "mode"
72 t.boolean "active"
72 t.boolean "active"
73 t.datetime "created_at", null: false
73 t.datetime "created_at", null: false
74 t.datetime "updated_at", null: false
74 t.datetime "updated_at", null: false
75 - t.integer "task_id", limit: 4
75 + t.integer "task_id"
76 - t.string "task_type", limit: 255
76 + t.string "task_type"
77 t.boolean "terminated"
77 t.boolean "terminated"
78 end
78 end
79
79
80 - add_index "grader_processes", ["host", "pid"], name: "index_grader_processes_on_ip_and_pid", using: :btree
80 + add_index "grader_processes", ["host", "pid"], name: "index_grader_processes_on_ip_and_pid"
81
81
82 create_table "heart_beats", force: :cascade do |t|
82 create_table "heart_beats", force: :cascade do |t|
83 - t.integer "user_id", limit: 4
83 + t.integer "user_id"
84 - t.string "ip_address", limit: 255
84 + t.string "ip_address"
85 t.datetime "created_at", null: false
85 t.datetime "created_at", null: false
86 t.datetime "updated_at", null: false
86 t.datetime "updated_at", null: false
87 - t.string "status", limit: 255
87 + t.string "status"
88 end
88 end
89
89
90 - add_index "heart_beats", ["updated_at"], name: "index_heart_beats_on_updated_at", using: :btree
90 + add_index "heart_beats", ["updated_at"], name: "index_heart_beats_on_updated_at"
91
91
92 create_table "languages", force: :cascade do |t|
92 create_table "languages", force: :cascade do |t|
93 t.string "name", limit: 10
93 t.string "name", limit: 10
94 - t.string "pretty_name", limit: 255
94 + t.string "pretty_name"
95 t.string "ext", limit: 10
95 t.string "ext", limit: 10
96 - t.string "common_ext", limit: 255
96 + t.string "common_ext"
97 end
97 end
98
98
99 create_table "logins", force: :cascade do |t|
99 create_table "logins", force: :cascade do |t|
100 - t.integer "user_id", limit: 4
100 + t.integer "user_id"
101 - t.string "ip_address", limit: 255
101 + t.string "ip_address"
102 t.datetime "created_at", null: false
102 t.datetime "created_at", null: false
103 t.datetime "updated_at", null: false
103 t.datetime "updated_at", null: false
104 end
104 end
105
105
106 create_table "messages", force: :cascade do |t|
106 create_table "messages", force: :cascade do |t|
107 - t.integer "sender_id", limit: 4
107 + t.integer "sender_id"
108 - t.integer "receiver_id", limit: 4
108 + t.integer "receiver_id"
109 - t.integer "replying_message_id", limit: 4
109 + t.integer "replying_message_id"
110 - t.text "body", limit: 65535
110 + t.text "body"
111 t.boolean "replied"
111 t.boolean "replied"
112 t.datetime "created_at", null: false
112 t.datetime "created_at", null: false
113 t.datetime "updated_at", null: false
113 t.datetime "updated_at", null: false
114 end
114 end
115
115
116 - create_table "problems", force: :cascade do |t|
116 + # Could not dump table "problems" because of following NoMethodError
117 - t.string "name", limit: 30
117 + # undefined method `[]' for nil:NilClass
118 - t.string "full_name", limit: 255
119 - t.integer "full_score", limit: 4
120 - t.date "date_added"
121 - t.boolean "available"
122 - t.string "url", limit: 255
123 - t.integer "description_id", limit: 4
124 - t.boolean "test_allowed"
125 - t.boolean "output_only"
126 - t.string "description_filename", limit: 255
127 - t.boolean "view_testcase"
128 - end
129
118
130 create_table "rights", force: :cascade do |t|
119 create_table "rights", force: :cascade do |t|
131 - t.string "name", limit: 255
120 + t.string "name"
132 - t.string "controller", limit: 255
121 + t.string "controller"
133 - t.string "action", limit: 255
122 + t.string "action"
134 end
123 end
135
124
136 create_table "rights_roles", id: false, force: :cascade do |t|
125 create_table "rights_roles", id: false, force: :cascade do |t|
137 - t.integer "right_id", limit: 4
126 + t.integer "right_id"
138 - t.integer "role_id", limit: 4
127 + t.integer "role_id"
139 end
128 end
140
129
141 - add_index "rights_roles", ["role_id"], name: "index_rights_roles_on_role_id", using: :btree
130 + add_index "rights_roles", ["role_id"], name: "index_rights_roles_on_role_id"
142
131
143 create_table "roles", force: :cascade do |t|
132 create_table "roles", force: :cascade do |t|
144 - t.string "name", limit: 255
133 + t.string "name"
145 end
134 end
146
135
147 create_table "roles_users", id: false, force: :cascade do |t|
136 create_table "roles_users", id: false, force: :cascade do |t|
148 - t.integer "role_id", limit: 4
137 + t.integer "role_id"
149 - t.integer "user_id", limit: 4
138 + t.integer "user_id"
150 end
139 end
151
140
152 - add_index "roles_users", ["user_id"], name: "index_roles_users_on_user_id", using: :btree
141 + add_index "roles_users", ["user_id"], name: "index_roles_users_on_user_id"
153
142
154 create_table "sessions", force: :cascade do |t|
143 create_table "sessions", force: :cascade do |t|
155 - t.string "session_id", limit: 255
144 + t.string "session_id"
156 - t.text "data", limit: 65535
145 + t.text "data"
157 t.datetime "updated_at"
146 t.datetime "updated_at"
158 end
147 end
159
148
160 - add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree
149 + add_index "sessions", ["session_id"], name: "index_sessions_on_session_id"
161 - add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree
150 + add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at"
162
151
163 create_table "sites", force: :cascade do |t|
152 create_table "sites", force: :cascade do |t|
164 - t.string "name", limit: 255
153 + t.string "name"
165 t.boolean "started"
154 t.boolean "started"
166 t.datetime "start_time"
155 t.datetime "start_time"
167 t.datetime "created_at", null: false
156 t.datetime "created_at", null: false
168 t.datetime "updated_at", null: false
157 t.datetime "updated_at", null: false
169 - t.integer "country_id", limit: 4
158 + t.integer "country_id"
170 - t.string "password", limit: 255
159 + t.string "password"
171 end
160 end
172
161
173 create_table "submission_view_logs", force: :cascade do |t|
162 create_table "submission_view_logs", force: :cascade do |t|
174 - t.integer "user_id", limit: 4
163 + t.integer "user_id"
175 - t.integer "submission_id", limit: 4
164 + t.integer "submission_id"
176 t.datetime "created_at", null: false
165 t.datetime "created_at", null: false
177 t.datetime "updated_at", null: false
166 t.datetime "updated_at", null: false
178 end
167 end
179
168
180 create_table "submissions", force: :cascade do |t|
169 create_table "submissions", force: :cascade do |t|
181 - t.integer "user_id", limit: 4
170 + t.integer "user_id"
182 - t.integer "problem_id", limit: 4
171 + t.integer "problem_id"
183 - t.integer "language_id", limit: 4
172 + t.integer "language_id"
184 - t.text "source", limit: 65535
173 + t.text "source"
185 - t.binary "binary", limit: 65535
174 + t.binary "binary"
186 t.datetime "submitted_at"
175 t.datetime "submitted_at"
187 t.datetime "compiled_at"
176 t.datetime "compiled_at"
188 - t.text "compiler_message", limit: 65535
177 + t.text "compiler_message"
189 t.datetime "graded_at"
178 t.datetime "graded_at"
190 - t.integer "points", limit: 4
179 + t.integer "points"
191 - t.text "grader_comment", limit: 65535
180 + t.text "grader_comment"
192 - t.integer "number", limit: 4
181 + t.integer "number"
193 - t.string "source_filename", limit: 255
182 + t.string "source_filename"
194 - t.float "max_runtime", limit: 24
183 + t.float "max_runtime"
195 - t.integer "peak_memory", limit: 4
184 + t.integer "peak_memory"
196 - t.integer "effective_code_length", limit: 4
185 + t.integer "effective_code_length"
197 - t.string "ip_address", limit: 255
186 + t.string "ip_address"
198 end
187 end
199
188
200 - add_index "submissions", ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true, using: :btree
189 + add_index "submissions", ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true
201 - add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree
190 + add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id"
202
191
203 create_table "tasks", force: :cascade do |t|
192 create_table "tasks", force: :cascade do |t|
204 - t.integer "submission_id", limit: 4
193 + t.integer "submission_id"
205 t.datetime "created_at"
194 t.datetime "created_at"
206 - t.integer "status", limit: 4
195 + t.integer "status"
207 t.datetime "updated_at"
196 t.datetime "updated_at"
208 end
197 end
209
198
210 create_table "test_pairs", force: :cascade do |t|
199 create_table "test_pairs", force: :cascade do |t|
211 - t.integer "problem_id", limit: 4
200 + t.integer "problem_id"
212 t.text "input", limit: 16777215
201 t.text "input", limit: 16777215
213 t.text "solution", limit: 16777215
202 t.text "solution", limit: 16777215
214 t.datetime "created_at", null: false
203 t.datetime "created_at", null: false
215 t.datetime "updated_at", null: false
204 t.datetime "updated_at", null: false
216 end
205 end
217
206
218 create_table "test_requests", force: :cascade do |t|
207 create_table "test_requests", force: :cascade do |t|
219 - t.integer "user_id", limit: 4
208 + t.integer "user_id"
220 - t.integer "problem_id", limit: 4
209 + t.integer "problem_id"
221 - t.integer "submission_id", limit: 4
210 + t.integer "submission_id"
222 - t.string "input_file_name", limit: 255
211 + t.string "input_file_name"
223 - t.string "output_file_name", limit: 255
212 + t.string "output_file_name"
224 - t.string "running_stat", limit: 255
213 + t.string "running_stat"
225 - t.integer "status", limit: 4
214 + t.integer "status"
226 t.datetime "updated_at", null: false
215 t.datetime "updated_at", null: false
227 t.datetime "submitted_at"
216 t.datetime "submitted_at"
228 t.datetime "compiled_at"
217 t.datetime "compiled_at"
229 - t.text "compiler_message", limit: 65535
218 + t.text "compiler_message"
230 t.datetime "graded_at"
219 t.datetime "graded_at"
231 - t.string "grader_comment", limit: 255
220 + t.string "grader_comment"
232 t.datetime "created_at", null: false
221 t.datetime "created_at", null: false
233 - t.float "running_time", limit: 24
222 + t.float "running_time"
234 - t.string "exit_status", limit: 255
223 + t.string "exit_status"
235 - t.integer "memory_usage", limit: 4
224 + t.integer "memory_usage"
236 end
225 end
237
226
238 - add_index "test_requests", ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id", using: :btree
227 + add_index "test_requests", ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id"
239
228
240 create_table "testcases", force: :cascade do |t|
229 create_table "testcases", force: :cascade do |t|
241 - t.integer "problem_id", limit: 4
230 + t.integer "problem_id"
242 - t.integer "num", limit: 4
231 + t.integer "num"
243 - t.integer "group", limit: 4
232 + t.integer "group"
244 - t.integer "score", limit: 4
233 + t.integer "score"
245 t.text "input", limit: 4294967295
234 t.text "input", limit: 4294967295
246 t.text "sol", limit: 4294967295
235 t.text "sol", limit: 4294967295
247 - t.datetime "created_at"
236 + t.datetime "created_at", null: false
248 - t.datetime "updated_at"
237 + t.datetime "updated_at", null: false
249 end
238 end
250
239
251 - add_index "testcases", ["problem_id"], name: "index_testcases_on_problem_id", using: :btree
240 + add_index "testcases", ["problem_id"], name: "index_testcases_on_problem_id"
252
241
253 create_table "user_contest_stats", force: :cascade do |t|
242 create_table "user_contest_stats", force: :cascade do |t|
254 - t.integer "user_id", limit: 4
243 + t.integer "user_id"
255 t.datetime "started_at"
244 t.datetime "started_at"
256 t.datetime "created_at", null: false
245 t.datetime "created_at", null: false
257 t.datetime "updated_at", null: false
246 t.datetime "updated_at", null: false
258 t.boolean "forced_logout"
247 t.boolean "forced_logout"
259 end
248 end
260
249
261 create_table "users", force: :cascade do |t|
250 create_table "users", force: :cascade do |t|
262 t.string "login", limit: 50
251 t.string "login", limit: 50
263 - t.string "full_name", limit: 255
252 + t.string "full_name"
264 - t.string "hashed_password", limit: 255
253 + t.string "hashed_password"
265 t.string "salt", limit: 5
254 t.string "salt", limit: 5
266 - t.string "alias", limit: 255
255 + t.string "alias"
267 - t.string "email", limit: 255
256 + t.string "email"
268 - t.integer "site_id", limit: 4
257 + t.integer "site_id"
269 - t.integer "country_id", limit: 4
258 + t.integer "country_id"
270 t.boolean "activated", default: false
259 t.boolean "activated", default: false
271 t.datetime "created_at"
260 t.datetime "created_at"
272 t.datetime "updated_at"
261 t.datetime "updated_at"
273 t.boolean "enabled", default: true
262 t.boolean "enabled", default: true
274 - t.string "remark", limit: 255
263 + t.string "remark"
275 - t.string "last_ip", limit: 255
264 + t.string "last_ip"
276 - t.string "section", limit: 255
265 + t.string "section"
277 end
266 end
278
267
279 - add_index "users", ["login"], name: "index_users_on_login", unique: true, using: :btree
268 + add_index "users", ["login"], name: "index_users_on_login", unique: true
280
269
281 end
270 end
@@ -1,15 +1,22
1 ENV["RAILS_ENV"] = "test"
1 ENV["RAILS_ENV"] = "test"
2 require File.expand_path('../../config/environment', __FILE__)
2 require File.expand_path('../../config/environment', __FILE__)
3 require 'rails/test_help'
3 require 'rails/test_help'
4
4
5 - #reporter
5 + #reporter for beautiful result
6 require "minitest/reporters"
6 require "minitest/reporters"
7 Minitest::Reporters.use!
7 Minitest::Reporters.use!
8
8
9 + module SignInHelper
10 + def sign_in_as(user,password)
11 + post login_login_path, {login: user, password: password }
12 + end
13 + end
14 +
9 class ActiveSupport::TestCase
15 class ActiveSupport::TestCase
16 + include SignInHelper
10 # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
17 # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
11 #
18 #
12 # Note: You'll currently still have to declare fixtures explicitly in integration tests
19 # Note: You'll currently still have to declare fixtures explicitly in integration tests
13 # -- they do not yet inherit this setting
20 # -- they do not yet inherit this setting
14 fixtures :all
21 fixtures :all
15
22
You need to be logged in to leave comments. Login now