Description:
[web] add test result page
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@159 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r79:bfeeb31156cf - - 5 files changed: 40 inserted, 3 deleted
@@ -1,11 +1,11 | |||||
|
1 | class TestController < ApplicationController |
|
1 | class TestController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :authenticate |
|
3 | before_filter :authenticate |
|
4 |
|
4 | ||
|
5 |
- verify :method => :post, :only => [: |
|
5 | + verify :method => :post, :only => [:submit], |
|
6 | :redirect_to => { :action => :index } |
|
6 | :redirect_to => { :action => :index } |
|
7 |
|
7 | ||
|
8 | def index |
|
8 | def index |
|
9 | @user = User.find(session[:user_id]) |
|
9 | @user = User.find(session[:user_id]) |
|
10 | prepare_index_information |
|
10 | prepare_index_information |
|
11 | @test_requests = @user.test_requests |
|
11 | @test_requests = @user.test_requests |
@@ -21,14 +21,18 | |||||
|
21 | redirect_to :action => 'index' |
|
21 | redirect_to :action => 'index' |
|
22 | end |
|
22 | end |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | def read |
|
25 | def read |
|
26 | user = User.find(session[:user_id]) |
|
26 | user = User.find(session[:user_id]) |
|
|
27 | + begin | ||
|
27 | test_request = TestRequest.find(params[:id]) |
|
28 | test_request = TestRequest.find(params[:id]) |
|
28 | - if test_request.user_id != user.id |
|
29 | + rescue |
|
|
30 | + test_request = nil | ||
|
|
31 | + end | ||
|
|
32 | + if test_request==nil or test_request.user_id != user.id | ||
|
29 | flash[:notice] = 'Invalid output' |
|
33 | flash[:notice] = 'Invalid output' |
|
30 | redirect_to :action => 'index' |
|
34 | redirect_to :action => 'index' |
|
31 | return |
|
35 | return |
|
32 | end |
|
36 | end |
|
33 | if test_request.output_file_name!=nil |
|
37 | if test_request.output_file_name!=nil |
|
34 | data = File.open(test_request.output_file_name).read(2048) |
|
38 | data = File.open(test_request.output_file_name).read(2048) |
@@ -40,12 +44,26 | |||||
|
40 | :type => 'text/plain'}) |
|
44 | :type => 'text/plain'}) |
|
41 | return |
|
45 | return |
|
42 | end |
|
46 | end |
|
43 | redirect_to :action => 'index' |
|
47 | redirect_to :action => 'index' |
|
44 | end |
|
48 | end |
|
45 |
|
49 | ||
|
|
50 | + def result | ||
|
|
51 | + @user = User.find(session[:user_id]) | ||
|
|
52 | + begin | ||
|
|
53 | + @test_request = TestRequest.find(params[:id]) | ||
|
|
54 | + rescue | ||
|
|
55 | + @test_request = nil | ||
|
|
56 | + end | ||
|
|
57 | + if @test_request==nil or @test_request.user_id != @user.id | ||
|
|
58 | + flash[:notice] = 'Invalid request' | ||
|
|
59 | + redirect_to :action => 'index' | ||
|
|
60 | + return | ||
|
|
61 | + end | ||
|
|
62 | + end | ||
|
|
63 | + | ||
|
46 | protected |
|
64 | protected |
|
47 |
|
65 | ||
|
48 | def prepare_index_information |
|
66 | def prepare_index_information |
|
49 | @submissions = Submission.find_last_for_all_available_problems(@user.id) |
|
67 | @submissions = Submission.find_last_for_all_available_problems(@user.id) |
|
50 | @problems = @submissions.collect { |submission| submission.problem } |
|
68 | @problems = @submissions.collect { |submission| submission.problem } |
|
51 | end |
|
69 | end |
@@ -1,2 +1,11 | |||||
|
1 | module TestHelper |
|
1 | module TestHelper |
|
|
2 | + | ||
|
|
3 | + def read_textfile(fname,max_size=2048) | ||
|
|
4 | + begin | ||
|
|
5 | + File.open(fname).read(max_size) | ||
|
|
6 | + rescue | ||
|
|
7 | + nil | ||
|
2 | end |
|
8 | end |
|
|
9 | + end | ||
|
|
10 | + | ||
|
|
11 | + end |
@@ -9,6 +9,7 | |||||
|
9 | %td= simple_format((test_request.running_stat or '')) |
|
9 | %td= simple_format((test_request.running_stat or '')) |
|
10 | %td{:align => "center"} |
|
10 | %td{:align => "center"} |
|
11 | - if test_request.output_file_name!=nil |
|
11 | - if test_request.output_file_name!=nil |
|
12 | = link_to '[output]', :action => 'read', :id => test_request.id |
|
12 | = link_to '[output]', :action => 'read', :id => test_request.id |
|
13 | %td= test_request.grader_comment or '' |
|
13 | %td= test_request.grader_comment or '' |
|
14 | %td= simple_format((test_request.compiler_message or '')) |
|
14 | %td= simple_format((test_request.compiler_message or '')) |
|
|
15 | + %td= link_to '[view]', :action => 'result', :id => test_request.id |
@@ -71,12 +71,13 | |||||
|
71 | <th>sub #</th> |
|
71 | <th>sub #</th> |
|
72 | <th>status</th> |
|
72 | <th>status</th> |
|
73 | <th>running stat</th> |
|
73 | <th>running stat</th> |
|
74 | <th>output (first 2kb)</th> |
|
74 | <th>output (first 2kb)</th> |
|
75 | <th>grading comment</th> |
|
75 | <th>grading comment</th> |
|
76 | <th>compiler message</th> |
|
76 | <th>compiler message</th> |
|
|
77 | + <th>Detail</th> | ||
|
77 | </tr> |
|
78 | </tr> |
|
78 | <%= render :partial => 'test_request', :collection => @test_requests %> |
|
79 | <%= render :partial => 'test_request', :collection => @test_requests %> |
|
79 | </table> |
|
80 | </table> |
|
80 |
|
81 | ||
|
81 | <% end %> |
|
82 | <% end %> |
|
82 |
|
83 |
@@ -11,32 +11,40 | |||||
|
11 | :user_id => 1, |
|
11 | :user_id => 1, |
|
12 | :problem => @problem, |
|
12 | :problem => @problem, |
|
13 | :language => @language, |
|
13 | :language => @language, |
|
14 | :source => 'sample source', |
|
14 | :source => 'sample source', |
|
15 | :compiler_message => 'none') |
|
15 | :compiler_message => 'none') |
|
16 | @user = mock(User, :id => 1, :login => 'john') |
|
16 | @user = mock(User, :id => 1, :login => 'john') |
|
17 | - Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) |
|
17 | + end |
|
|
18 | + | ||
|
|
19 | + it "should redirect user to login page when unlogged-in user try to access main/list" do | ||
|
|
20 | + get 'list' | ||
|
|
21 | + response.should redirect_to(:action => 'login') | ||
|
18 | end |
|
22 | end |
|
19 |
|
23 | ||
|
20 | it "should let user sees her own source" do |
|
24 | it "should let user sees her own source" do |
|
|
25 | + Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) | ||
|
21 | get 'source', {:id => @submission.id}, {:user_id => 1} |
|
26 | get 'source', {:id => @submission.id}, {:user_id => 1} |
|
22 | response.should be_success |
|
27 | response.should be_success |
|
23 | end |
|
28 | end |
|
24 |
|
29 | ||
|
25 | it "should let user sees her own compiler message" do |
|
30 | it "should let user sees her own compiler message" do |
|
|
31 | + Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) | ||
|
26 | get 'compiler_msg', {:id => @submission.id}, {:user_id => 1} |
|
32 | get 'compiler_msg', {:id => @submission.id}, {:user_id => 1} |
|
27 | response.should be_success |
|
33 | response.should be_success |
|
28 | end |
|
34 | end |
|
29 |
|
35 | ||
|
30 | it "should not let user sees other user's source" do |
|
36 | it "should not let user sees other user's source" do |
|
|
37 | + Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) | ||
|
31 | get 'source', {:id => @submission.id}, {:user_id => 2} |
|
38 | get 'source', {:id => @submission.id}, {:user_id => 2} |
|
32 | flash[:notice].should =~ /[Ee]rror/ |
|
39 | flash[:notice].should =~ /[Ee]rror/ |
|
33 | response.should redirect_to(:action => 'list') |
|
40 | response.should redirect_to(:action => 'list') |
|
34 | end |
|
41 | end |
|
35 |
|
42 | ||
|
36 | it "should not let user sees other user's compiler message" do |
|
43 | it "should not let user sees other user's compiler message" do |
|
|
44 | + Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) | ||
|
37 | get 'compiler_msg', {:id => @submission.id}, {:user_id => 2} |
|
45 | get 'compiler_msg', {:id => @submission.id}, {:user_id => 2} |
|
38 | flash[:notice].should =~ /[Ee]rror/ |
|
46 | flash[:notice].should =~ /[Ee]rror/ |
|
39 | response.should redirect_to(:action => 'list') |
|
47 | response.should redirect_to(:action => 'list') |
|
40 | end |
|
48 | end |
|
41 |
|
49 | ||
|
42 | end |
|
50 | end |
You need to be logged in to leave comments.
Login now