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: 41 inserted, 4 deleted
@@ -1,53 +1,71 | |||
|
1 | 1 | class TestController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate |
|
4 | 4 | |
|
5 |
- verify :method => :post, :only => [: |
|
|
5 | + verify :method => :post, :only => [:submit], | |
|
6 | 6 | :redirect_to => { :action => :index } |
|
7 | 7 | |
|
8 | 8 | def index |
|
9 | 9 | @user = User.find(session[:user_id]) |
|
10 | 10 | prepare_index_information |
|
11 | 11 | @test_requests = @user.test_requests |
|
12 | 12 | end |
|
13 | 13 | |
|
14 | 14 | def submit |
|
15 | 15 | @user = User.find(session[:user_id]) |
|
16 | 16 | test_request = TestRequest.new_from_form_params(@user,params[:test_request]) |
|
17 | 17 | if test_request.save |
|
18 | 18 | redirect_to :action => 'index' |
|
19 | 19 | else |
|
20 | 20 | flash[:notice] = 'Error saving your test submission' |
|
21 | 21 | redirect_to :action => 'index' |
|
22 | 22 | end |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | def read |
|
26 | 26 | user = User.find(session[:user_id]) |
|
27 | - test_request = TestRequest.find(params[:id]) | |
|
28 | - if test_request.user_id != user.id | |
|
27 | + begin | |
|
28 | + test_request = TestRequest.find(params[:id]) | |
|
29 | + rescue | |
|
30 | + test_request = nil | |
|
31 | + end | |
|
32 | + if test_request==nil or test_request.user_id != user.id | |
|
29 | 33 | flash[:notice] = 'Invalid output' |
|
30 | 34 | redirect_to :action => 'index' |
|
31 | 35 | return |
|
32 | 36 | end |
|
33 | 37 | if test_request.output_file_name!=nil |
|
34 | 38 | data = File.open(test_request.output_file_name).read(2048) |
|
35 | 39 | if data==nil |
|
36 | 40 | data="" |
|
37 | 41 | end |
|
38 | 42 | send_data(data, |
|
39 | 43 | {:filename => 'output.txt', |
|
40 | 44 | :type => 'text/plain'}) |
|
41 | 45 | return |
|
42 | 46 | end |
|
43 | 47 | redirect_to :action => 'index' |
|
44 | 48 | end |
|
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 | |
|
45 | 63 | |
|
46 | 64 | protected |
|
47 | 65 | |
|
48 | 66 | def prepare_index_information |
|
49 | 67 | @submissions = Submission.find_last_for_all_available_problems(@user.id) |
|
50 | 68 | @problems = @submissions.collect { |submission| submission.problem } |
|
51 | 69 | end |
|
52 | 70 | |
|
53 | 71 | end |
@@ -1,2 +1,11 | |||
|
1 | 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 | |
|
8 | + end | |
|
9 | + end | |
|
10 | + | |
|
2 | 11 | end |
@@ -3,12 +3,13 | |||
|
3 | 3 | = format_short_time(test_request.submitted_at) |
|
4 | 4 | %td= test_request.problem.full_name |
|
5 | 5 | %td{:align => "center"} |
|
6 | 6 | = test_request.submission.number |
|
7 | 7 | %td{:align => "center"} |
|
8 | 8 | = test_request.status_str |
|
9 | 9 | %td= simple_format((test_request.running_stat or '')) |
|
10 | 10 | %td{:align => "center"} |
|
11 | 11 | - if test_request.output_file_name!=nil |
|
12 | 12 | = link_to '[output]', :action => 'read', :id => test_request.id |
|
13 | 13 | %td= test_request.grader_comment or '' |
|
14 | 14 | %td= simple_format((test_request.compiler_message or '')) |
|
15 | + %td= link_to '[view]', :action => 'result', :id => test_request.id |
@@ -65,18 +65,19 | |||
|
65 | 65 | <h3>Previous requests</h3> |
|
66 | 66 | |
|
67 | 67 | <table class="info"> |
|
68 | 68 | <tr class="info-head"> |
|
69 | 69 | <th>at</th> |
|
70 | 70 | <th>problem</th> |
|
71 | 71 | <th>sub #</th> |
|
72 | 72 | <th>status</th> |
|
73 | 73 | <th>running stat</th> |
|
74 | 74 | <th>output (first 2kb)</th> |
|
75 | 75 | <th>grading comment</th> |
|
76 | 76 | <th>compiler message</th> |
|
77 | + <th>Detail</th> | |
|
77 | 78 | </tr> |
|
78 | 79 | <%= render :partial => 'test_request', :collection => @test_requests %> |
|
79 | 80 | </table> |
|
80 | 81 | |
|
81 | 82 | <% end %> |
|
82 | 83 |
@@ -5,38 +5,46 | |||
|
5 | 5 | |
|
6 | 6 | before(:each) do |
|
7 | 7 | @problem = mock(Problem, :name => 'test') |
|
8 | 8 | @language = mock(Language, :name => 'cpp', :ext => 'cpp') |
|
9 | 9 | @submission = mock(Submission, |
|
10 | 10 | :id => 1, |
|
11 | 11 | :user_id => 1, |
|
12 | 12 | :problem => @problem, |
|
13 | 13 | :language => @language, |
|
14 | 14 | :source => 'sample source', |
|
15 | 15 | :compiler_message => 'none') |
|
16 | 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 | 22 | end |
|
19 | 23 | |
|
20 | 24 | it "should let user sees her own source" do |
|
25 | + Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) | |
|
21 | 26 | get 'source', {:id => @submission.id}, {:user_id => 1} |
|
22 | 27 | response.should be_success |
|
23 | 28 | end |
|
24 | 29 | |
|
25 | 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 | 32 | get 'compiler_msg', {:id => @submission.id}, {:user_id => 1} |
|
27 | 33 | response.should be_success |
|
28 | 34 | end |
|
29 | 35 | |
|
30 | 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 | 38 | get 'source', {:id => @submission.id}, {:user_id => 2} |
|
32 | 39 | flash[:notice].should =~ /[Ee]rror/ |
|
33 | 40 | response.should redirect_to(:action => 'list') |
|
34 | 41 | end |
|
35 | 42 | |
|
36 | 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 | 45 | get 'compiler_msg', {:id => @submission.id}, {:user_id => 2} |
|
38 | 46 | flash[:notice].should =~ /[Ee]rror/ |
|
39 | 47 | response.should redirect_to(:action => 'list') |
|
40 | 48 | end |
|
41 | 49 | |
|
42 | 50 | end |
You need to be logged in to leave comments.
Login now