Description:
[web] improving readability of test_interface, re: ticket #10
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@141 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
r64:f6cdb5f921b2 - - 5 files changed: 6 inserted, 5 deleted
@@ -1,34 +1,35 | |||
|
1 | 1 | class TestController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate |
|
4 | 4 | |
|
5 | 5 | verify :method => :post, :only => [:test_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 | + @test_requests = @user.test_requests | |
|
11 | 12 | end |
|
12 | 13 | |
|
13 | 14 | def submit |
|
14 | 15 | @user = User.find(session[:user_id]) |
|
15 | 16 | test_request = TestRequest.new_from_form_params(@user,params[:test_request]) |
|
16 | 17 | if test_request.save |
|
17 | 18 | redirect_to :action => 'index' |
|
18 | 19 | else |
|
19 | 20 | flash[:notice] = 'Error saving your test submission' |
|
20 | 21 | redirect_to :action => 'index' |
|
21 | 22 | end |
|
22 | 23 | end |
|
23 | 24 | |
|
24 | 25 | def read |
|
25 | 26 | user = User.find(session[:user_id]) |
|
26 | 27 | test_request = TestRequest.find(params[:id]) |
|
27 | 28 | if test_request.user_id != user.id |
|
28 | 29 | flash[:notice] = 'Invalid output' |
|
29 | 30 | redirect_to :action => 'index' |
|
30 | 31 | return |
|
31 | 32 | end |
|
32 | 33 | if test_request.output_file_name!=nil |
|
33 | 34 | data = File.open(test_request.output_file_name).read(2048) |
|
34 | 35 | if data==nil |
@@ -1,31 +1,31 | |||
|
1 | 1 | require 'digest/sha1' |
|
2 | 2 | |
|
3 | 3 | class User < ActiveRecord::Base |
|
4 | 4 | |
|
5 | 5 | has_and_belongs_to_many :roles |
|
6 | 6 | |
|
7 |
- has_many :test_requests, :order => " |
|
|
7 | + has_many :test_requests, :order => "submitted_at DESC" | |
|
8 | 8 | |
|
9 | 9 | validates_presence_of :login |
|
10 | 10 | validates_presence_of :full_name |
|
11 | 11 | validates_length_of :full_name, :minimum => 1 |
|
12 | 12 | |
|
13 | 13 | validates_presence_of :password, :if => :password_required? |
|
14 | 14 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
15 | 15 | validates_confirmation_of :password, :if => :password_required? |
|
16 | 16 | |
|
17 | 17 | attr_accessor :password |
|
18 | 18 | |
|
19 | 19 | before_save :encrypt_new_password |
|
20 | 20 | |
|
21 | 21 | def self.authenticate(login, password) |
|
22 | 22 | user = find_by_login(login) |
|
23 | 23 | return user if user && user.authenticated?(password) |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def authenticated?(password) |
|
27 | 27 | hashed_password == User.encrypt(password,self.salt) |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | def admin? |
|
31 | 31 | self.roles.detect {|r| r.name == 'admin' } |
@@ -1,11 +1,11 | |||
|
1 | 1 | %tr{:class => (test_request_counter%2==0) ? "info-even" : "info-odd"} |
|
2 | 2 | %td= test_request_counter +1 |
|
3 | 3 | %td= test_request.problem.full_name |
|
4 | 4 | %td= test_request.submission.number |
|
5 | 5 | %td= test_request.status_str |
|
6 | - %td= test_request.running_stat or '' | |
|
6 | + %td= simple_format((test_request.running_stat or '')) | |
|
7 | 7 | %td |
|
8 | 8 | - if test_request.output_file_name!=nil |
|
9 | 9 | = link_to '[output]', :action => 'read', :id => test_request.id |
|
10 | 10 | %td= test_request.grader_comment or '' |
|
11 | - %td= test_request.compiler_message or '' | |
|
11 | + %td= simple_format((test_request.compiler_message or '')) |
@@ -45,29 +45,29 | |||
|
45 | 45 | <tr> |
|
46 | 46 | <td>Input data:</td> |
|
47 | 47 | <td><%= f.file_field :input_file %></td> |
|
48 | 48 | <tr> |
|
49 | 49 | <td colspan="2"> |
|
50 | 50 | <%= submit_tag 'submit' %> |
|
51 | 51 | </td> |
|
52 | 52 | </tr> |
|
53 | 53 | </table> |
|
54 | 54 | <% end %> |
|
55 | 55 | |
|
56 | 56 | <h3>Previous requests</h3> |
|
57 | 57 | |
|
58 | 58 | <table class="info"> |
|
59 | 59 | <tr class="info-head"> |
|
60 | 60 | <th></td> |
|
61 | 61 | <th>problem</th> |
|
62 | 62 | <th>#</th> |
|
63 | 63 | <th>status</th> |
|
64 | 64 | <th>running stat</th> |
|
65 | 65 | <th>output (first 2kb)</th> |
|
66 | 66 | <th>grading comment</th> |
|
67 | 67 | <th>compiler message</th> |
|
68 | 68 | </tr> |
|
69 |
- <%= render :partial => 'test_request', :collection => @ |
|
|
69 | + <%= render :partial => 'test_request', :collection => @test_requests %> | |
|
70 | 70 | </table> |
|
71 | 71 | |
|
72 | 72 | <% end %> |
|
73 | 73 |
@@ -1,28 +1,28 | |||
|
1 | 1 | |
|
2 | 2 | require File.dirname(__FILE__) + '/../spec_helper' |
|
3 | 3 | |
|
4 | - describe Submission do | |
|
4 | + describe Submission, "when verifying user submission" do | |
|
5 | 5 | |
|
6 | 6 | before(:each) do |
|
7 | 7 | @submission = Submission.new |
|
8 | 8 | @submission.source = <<SOURCE |
|
9 | 9 | /* |
|
10 | 10 | LANG: C++ |
|
11 | 11 | TASK: testproblem |
|
12 | 12 | */ |
|
13 | 13 | SOURCE |
|
14 | 14 | end |
|
15 | 15 | |
|
16 | 16 | it "should find language in source" do |
|
17 | 17 | langcpp = stub(Language, :name => 'cpp', :ext => 'cpp') |
|
18 | 18 | Language.should_receive(:find_by_name).with('C++').and_return(langcpp) |
|
19 | 19 | Submission.find_language_in_source(@submission.source).should == langcpp |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | it "should find problem in source, when there is any" do |
|
23 | 23 | problem = stub(Problem, :name => 'testproblem') |
|
24 | 24 | Problem.should_receive(:find_by_name).with('testproblem').and_return(problem) |
|
25 | 25 | Submission.find_problem_in_source(@submission.source).should == problem |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | it "should return nil when it cannot find problem in source" do |
You need to be logged in to leave comments.
Login now