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:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r79:bfeeb31156cf - - 5 files changed: 41 inserted, 4 deleted

@@ -2,7 +2,7
2 2
3 3 before_filter :authenticate
4 4
5 - verify :method => :post, :only => [:test_submit],
5 + verify :method => :post, :only => [:submit],
6 6 :redirect_to => { :action => :index }
7 7
8 8 def index
@@ -24,8 +24,12
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
@@ -42,6 +46,20
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
@@ -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
@@ -12,3 +12,4
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
@@ -74,6 +74,7
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>
@@ -14,26 +14,34
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')
You need to be logged in to leave comments. Login now